2017-06-05 57 views
0

String.Format在千位添加逗号只需添加空格而不用逗号。String.Format()在数以千计的位置添加逗号以使数字不起作用

我想:

var total = string.Format("{0:n0}", 12345); 
// expect: total = 12,345 
// actual: total = 12 345 

什么我失踪?

+0

可能的复制.Format()在数千个位置添加逗号](https://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a- number ) – Liam

+3

你错过了更新你的SO配置文件,所以我们可以告诉你在哪里 你住在。确切的格式是文化特定的,可以用控制面板覆盖。如果您坚持使用逗号,请考虑使用CultureInfo.InvariantCulture.NumberFormat。 –

+0

这取决于您当前的文化设置。 – Reniuz

回答

5

这是一种文化的东西。在你的语言环境中,显然,空格是数千个说明符。我看到逗号。要查看特定语言环境的输出,请明确指定。一个非常常见的选项是 “不变”:

var total = string.Format(CultureInfo.InvariantCulture, "{0:n0}", 12345); 
3

这好像是您的PC上您的区域设置:

enter image description here

DEMO工作[.NET字符串的精细

+0

这将工作到你把它放在另一台PC上 – Liam

相关问题