- How, for example, do I turn the number 10562.3093 into 10,562 in C#?
- Also, how do I ensure that same formatter will apply correctly to all other numbers?....
- ...For example 2500.32 into 2,500
Help greatly appreciated.
Help greatly appreciated.
String.Format("{0:0,0}", 10562.3093);
I keep this website bookmarked for these purposes: String Formatting in C#
double x = 10562.3093;
x.ToString("#,0");
or
String.Format("{0:#,0}", 10562.3093);
string formatted = value.ToString("N0");
This divides your number in the manner specified by the current culture (in the case of "en-US," it's a comma per multiple of 1000) and includes no decimal places.
The best place to look for any question regarding formatting numbers in .NET would have to be here:
Standard Numeric Format Strings (MSDN)
And here: