Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display 1 instead of 01 in ToString();

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

like image 754
Xaisoft Avatar asked Dec 05 '25 06:12

Xaisoft


2 Answers

ToString("#,0")

Also, this may help you further

like image 103
juan Avatar answered Dec 07 '25 21:12

juan


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.

like image 32
achinda99 Avatar answered Dec 07 '25 19:12

achinda99



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!