String.Format an integer to use 1000's separator without leading 0 for small integers

Posted by Kragen on Stack Overflow See other posts from Stack Overflow or by Kragen
Published on 2009-11-03T09:56:49Z Indexed on 2010/06/16 13:02 UTC
Read the original article Hit count: 363

Filed under:
|

Silly question, I want to format an integer so that it appears with the 1000's separator (,), but also without decimal places and without a leading 0.

My attempts so far have been:

String.Format("{0} {1}", 5, 5000);            // 5 5000
String.Format("{0:n} {1:n}", 5, 5000);        // 5.00 5,000.00
String.Format("{0:0,0} {1:0,0}", 5, 5000);    // 05 5,000

The output I'm after is:

5 5,000

Is there something obvious that I'm missing?

© Stack Overflow or respective owner

Related posts about c#

Related posts about string-formatting