Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number Formatting in Thousands

  • 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.

like image 855
Goober Avatar asked Jul 27 '10 17:07

Goober


2 Answers

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:

Custom Numeric Format Strings (MSDN)

like image 60
Dan Tao Avatar answered Nov 11 '22 23:11

Dan Tao


string.Format("{0:n0}", 10562.3093);
like image 43
dcp Avatar answered Nov 12 '22 00:11

dcp