使用 String.Format 如何确保所有数字在每 3 位数字后都有逗号 例如 23000 = "23,000"并且 0 返回 "0"。
String.Format("{0:n}", 0);//给出我不想要的 0.00。 我不需要任何小数位,所有数字都是整数。
最佳答案
你可以这样做,我发现这样更清晰地阅读了以下内容的意图:
String.Format("{0:#,###0}", 0);
例子:
string.Format("{0:#,###0}", 123456789); // 123,456,789
string.Format("{0:#,###0}", 0); // 0
关于c# - 使用 String.Format 为数字添加逗号和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2545633/