Click here to Skip to main content
15,914,165 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


I have values as 0,1,2 ......so on.I have converted it into double after that I round off it to 1 decimal place.It is working fine for values having digit after decimal but bot working fine if the digit is 100 or numbers without having digits after decimal. I want result as 100.0 for 100 and so on.

Please Help
Posted

Since, the 0 after the decimal point without any number following it does not have any significance as a value it is not available in the double value.

However, while representing the double number as a string it can be shown using an appropriate Format specifier as follows:
C#
double value = 100;
string valueAsString = value.ToString("N1");
Console.WriteLine (valueAsString);
//Output
//100.0

To show commas etc. other Formats given here http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.71).aspx[^] can be used.
 
Share this answer
 
v4
Comments
Manas Bhardwaj 9-Jun-12 6:13am    
good answer +5!
VJ Reddy 9-Jun-12 6:15am    
Thank you, Manas :)
lblshowresult.Text = String.Format("{0:INR #,##0.00}", Convert.ToDecimal(SumTotal));
 
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