Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
i have a price like

eg.: 55.65 or 23.23

I want to round off if , so it will show as

55.65 = 56

23.23 = 23

and then show as 56,00 and 23,00


also if price is 1000 show as 1,000




regards
maulik shah
Posted

I don't think you really need to round off anything. I think you need to present some rounded value, and this is no the same. This is just a matter of proper formatting of the string representing some numeric value. Please see:
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx[^].

This approach (when you never explicitly round off anything) has one important benefit: you don't risk using the rounded value in further calculations, which could accidentally cause some loss of accuracy. With just formatting, you cannot go wrong, because rounding is actually hidden from you, it happens inside ToString(string).

—SA
 
Share this answer
 
Hello ,

You can try this way

firstly module (%) the decimal number by 1 , so that i can check whether the remainder is greater than or less than 0.5 . depending upon the condition i rounding off the given decimal no.

<br />
decimal val = 512432435.65m;<br />
decimal ulti = ((val % 1) > 0.5m ? val - (val % 1) + 1 : val - (val % 1));<br />
Console.WriteLine(ulti.ToString("#,##0.00##"));<br />

thanks
 
Share this answer
 
Hi,
For round of
C#
int finalprice =Convert.ToInt32( Math.Round(55.65, 0));//56
       int finalprice1 = Convert.ToInt32(Math.Round(55.5, MidpointRounding.AwayFromZero));//56
       int finalprice2 = Convert.ToInt32(Math.Round(23.23, 0));//23

For currency separator follow the link
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^]
 
Share this answer
 
v3
Try this

C#
double inputValue = 1000; 
        Label1.Text = Convert.ToDouble(inputValue).ToString(("#,##0")); //1,000
        double num = 56.75;
        num = Math.Round(num,0);//57
        string s = num.ToString("0.00", CultureInfo.InvariantCulture);//57.00
        Label1.Text = s.Replace('.', ',')//57,00 ;
 
Share this answer
 
v2
Comments
Raajkumar.b 11-Mar-14 4:21am    
why my answer is downvoted?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900