Formatting numbers in thousands

  • How, for example, can I turn the number 10562.3093 into 10 562 in C #?
  • Also, how can I guarantee that the same formatter will correctly apply to all other numbers? ....
  • ... for example 2500.32 to 2,500

Help with thanks.

+5
source share
4 answers
string formatted = value.ToString("N0");

This divides your number according to the current culture (in the case of "en-US", this is a comma by several 1000) and does not contain decimal places.

The best place to look for any question regarding .NET formatting numbers should be here:

Standard Number Format Strings (MSDN)

And here:

(MSDN)

+2
string.Format("{0:n0}", 10562.3093);
+2
String.Format("{0:0,0}", 10562.3093);

: #

+1
double x = 10562.3093;
x.ToString("#,0");

String.Format("{0:#,0}", 10562.3093);
0
source

All Articles