如何在ToString()中显示1而不是01;

时间:2023-01-14 15:23:50

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

我使用格式ToString(“0,0”)来显示一个数字

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

3 个解决方案

#1


ToString("#,0")

Also, this may help you further

此外,这可能会进一步帮助您

#2


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

你要找的是字符串格式化程序“N0”。例:

int x = 10000;
int y = 5;

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

Prints:

10,000
5

More information here.

更多信息在这里。

#3


ToString("N0")

#1


ToString("#,0")

Also, this may help you further

此外,这可能会进一步帮助您

#2


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

你要找的是字符串格式化程序“N0”。例:

int x = 10000;
int y = 5;

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

Prints:

10,000
5

More information here.

更多信息在这里。

#3


ToString("N0")