.net - String.Format - 整数,千位分隔符,无小数

标签 .net string.format

用千位分隔符(逗号)和没有小数位格式化整数的最简单的 String.Format 模板是什么? en-美国文化。所需格式的示例:

1200 = 1,200

900 = 900

8 = 8

谢谢!

最佳答案

N0 是您要查找的格式。
N 将用逗号格式化,0 是告诉它不使用小数:

// will format as 33,540
string.Format("{0:N0}", 33540.54M)

// example using an integer: 1,200
string.Format("{0:N0}", 1200);

来自 MSDN :

Result: Integral and decimal digits, group separators, and a decimal separator with optional negative sign. Supported by: All numeric types. Precision specifier: Desired number of decimal places. Default precision specifier: Defined byNumberFormatInfo.NumberDecimalDigits. More information: The Numeric ("N") Format Specifier.

关于.net - String.Format - 整数,千位分隔符,无小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24516037/

相关文章:

.net - 小型 .net/php 开发商店的推荐设置是什么?

c# toString() 性能

c# - 字符串输出 : format or concat in C#?

html - @Html.TextBoxFor 验证

c# - SaveAs 方法配置为需要有根路径,而路径 'fp' 没有根

c# - 在 Silverlight 中重新抛出异常时保留堆栈跟踪

c# - 批准测试抛出 System.MissingMethodException

c# - 在 C# 中使用字符串格式的刹车线和粗体文本

仅 Java 字符串格式小数

c# - 解释日期 : Console. Writeline 与 string.Format