<分区>
Possible Duplicate:
.NET String.Format() to add commas in thousands place for a number
你好
我有那样的金钱值(value)
12345
123456
1234567
1234567,89
我想要的格式是这样的。
12,345
123,456
1,234,567
1,234,567, 89
我如何使用 String.Format 做到这一点?
标签 c# .net string formatting format
<分区>
Possible Duplicate:
.NET String.Format() to add commas in thousands place for a number
你好
我有那样的金钱值(value)
12345
123456
1234567
1234567,89
我想要的格式是这样的。
12,345
123,456
1,234,567
1,234,567, 89
我如何使用 String.Format 做到这一点?
最佳答案
String.Format("{0:c}");
这将根据客户端的区域设置将您的数字格式化为货币格式。
如果您的客户所在的地区是在欧洲,则结果为 12.134,45 美元,因为那里就是这样做的。
这是货币格式的首选方法,如果您只想专门获取逗号而不是 $,您可能必须使用“{0:#,##0}”或类似的内容来完成。
关于C# 字符串格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5426294/