Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sir i have a double type of variable and it's contain a value like (113976.84375)

but i don't want to show value in this format i only want to show (113976.84)

but i don't know how it done...
so help me.
Posted
Updated 23-May-18 21:10pm
v2

C#
double var1 = 113976.84375;
double var2 = Math.Round(var1,2) ;

or
C#
double var1 = 113976.84375;
double var2 = Convert.ToDouble(var1.ToString("0.00"));

Happy Coding!
:)
 
Share this answer
 
Comments
Shambhoo kumar 24-Aug-12 0:56am    
Thanks mam...
Aarti Meswania 24-Aug-12 0:58am    
welcome :)
something like this:

String.Format("{0:0.00}", 113976.84375); 


read more here:

http://www.csharp-examples.net/string-format-double/[^]
 
Share this answer
 
Comments
Shambhoo kumar 23-Aug-12 8:03am    
str = "113976.84375";
str = string.Format("{0:0.00}", str);
label17.Text = str;

i want to write variable name on the place of value ..but it not work....
fjdiewornncalwe 23-Aug-12 14:34pm    
Your "str" variable needs to be of type double for the format statement to work. If you have it as a string you need to Convert.ToDouble(str) first and then the format will work.
To format the number you can use,
C#
string.Format("{0:0.00}", 113976.84375);

If you want to round it to 2 decimal places then you can to use,
C#
Math.Round(113976.84375,2);
 
Share this answer
 
Comments
Shambhoo kumar 23-Aug-12 8:30am    
Thanks sir..
 
Share this answer
 
Comments
Shambhoo kumar 23-Aug-12 8:30am    
Thanks for recomend.
decimal.Round(yourValue, 2, MidpointRounding.AwayFromZero);
 
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