net string format()在数字中为千位添加逗号


我想在一个数字的上千个地方添加一个逗号。 <代码>的String.Format()

String.Format("{0:n}", 1234); //Output: 1,234.00

string.Format("{0:n0}", 9876); // no digits after the decimal point. Output: 9,876

我发现这是最简单的方法:

myInteger.ToString("N0")

未经作者同意,本文严禁转载,违者必究!