题
int a = 10000000;
a.ToString();
我如何使输出?
10,000,000
解决方案
尝试N0
为没有小数部分:
string formatted = a.ToString("N0"); // 10,000,000
其他提示
您也可以做的String.Format:
int x = 100000;
string y = string.Empty;
y = string.Format("{0:#,##0.##}", x);
//Will output: 100,000
如果你有小数,相同的代码将输出2位小数:
double x = 100000.2333;
string y = string.Empty;
y = string.Format("{0:#,##0.##}", x);
//Will output: 100,000.23
要作出的,而不是使用小数逗号这样:
double x = 100000.2333;
string y = string.Empty;
y = string.Format(System.Globalization.CultureInfo.GetCultureInfo("de-DE"), "{0:#,##0.##}", x);
a.ToString("N0")
一个简单的String.Format选项:
int a = 10000000;
String.Format("{0:n0}", a); //10,000,000
a.tostring( “00000000”)
不隶属于 StackOverflow