views:

431

answers:

3

Hello,

I am using the format ToString("0,0") to display a number like

5000 as 5,000
but if the number is 0 - 9, it displays 01, 02, 03, etc. Does anyone know the correct syntax so it does not display the leading 0?

Thanks, XaiSoft

+14  A: 
ToString("#,0")

Also, this may help you further

Juan Manuel
+1 for cheat sheet link
geofftnz
He, thanks. I just found it today, it has a lot more also very useful
Juan Manuel
+1  A: 
ToString("N0")
LukeH
On first sight, I thought this was a humorous answer saying "No, I don't know how to...". Then I realised that Oh was a Zero...
paxdiablo
+2  A: 

What you are looking for is the string formatter "N0". Example:

int x = 10000;
int y = 5;

Console.WriteLine(x.ToString("N0"));
Console.WriteLine(y.ToString("N0"));

Prints:

10,000
5

More information here.

achinda99