Click here to Skip to main content
15,878,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using .net windows form application.

I use convert::tostring to convert a double value to string.

How do I convert it to a 2 decimal point number?

If my double value is 23, I want it to show as 23.00.

How to do that??
Updated 6-Sep-10 21:21pm
Dalek Dave 7-Sep-10 3:21am    
~Minor Edit for Grammar.

1 solution

You may use directly the Double.ToString method for the purpose (see "Custom Numeric Format Strings" at MSDN[^]):
double d = 23;
string s = d.ToString("0.00", CultureInfo.InvariantCulture);

Share this answer
tuolesi 7-Sep-10 4:20am    
thx,it works for me.

But i saw the Convert::toString method can also accepet an overloading of Convert::ToString(Double, IFormatProvider).Can this method used to format the string?If yes,how?
CPallini 7-Sep-10 4:41am    
I guess you've to create a new NumberFormatInfo object, customize it (see for instance ) and finally pass it as IFormatProvider parameter.

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