gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 20:36:22 25 4
gpt4 key购买 nike

用千位分隔符(逗号)和没有小数位格式化整数的最简单的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com