Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Round off A decimal number..?
suppose I have a number like 25.75,and I have to round it into 26.00.so how to solve this through code i donot understand.so please help me out..its urgent.I have to solve in windows application.
Posted

C#
decimal d= 25.75;
d = Math.Round(d);// so, d=26
string a = d.ToString("0.00");//to show it in textbox in 0.00 format

Happy Coding!
:)
 
Share this answer
 
v2
Comments
ridoy 7-Sep-12 1:44am    
right..+5
Aarti Meswania 7-Sep-12 1:50am    
thank you! :)
Shivani Dash 7-Sep-12 2:00am    
Thank u AArti.....Thanks a lot.it works.i also had donbe this bt didnt knw the right way to use math.round functn.so thanks 4 help.... :D

Hv also another questn related 2 this,if u can plz help me.
Aarti Meswania 7-Sep-12 2:02am    
welcome :)
I will try to help you. what is that Question?
Shivani Dash 7-Sep-12 2:02am    
suppose hv a datagridview.and hving two column of price.after rounding the rate i wnt to add bth of them and have to show in a textbox.hw to do?
 
Share this answer
 
v2
Try this
C#
Console.WriteLine("Math.Ceiling(25.75) = {0}", Math.Ceiling(25.75));
Console.WriteLine("Math.Ceiling(25.45) = {0}", Math.Ceiling(25.45));
Console.WriteLine("Math.Floor(25.75) = {0}", Math.Floor(25.75));
Console.WriteLine("Math.Floor(25.45) = {0}", Math.Floor(25.45));
Console.WriteLine("Math.Round(25.75) = {0}", Math.Round(25.75));
Console.WriteLine("Math.Round(25.45) = {0}", Math.Round(25.45));
 
Share this answer
 
Comments
Shivani Dash 7-Sep-12 2:41am    
sorry bt didnt get u....if u gv me ur id i'll better explain i think.
use these:

Math.Ceiling(25.75); -> 26 it results in next biggest value
Math.Floor(25.45); -> 25 it results in next biggest value
Math.Round(25.75); -> 25 or 26 based upon the value after the (.) value
 
Share this answer
 

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