此代码来自 Charles Pettzold 的“Programming Windows Sixth Edition”一书:
public object Convert(object value, Type targetType, object parameter, string language)
{
return ((double)value).ToString("N0");
}
ToString("N0")
应该打印带有逗号分隔符且没有小数点的值。我在文档中找不到对适当的 ToString
重载和 "N0"
格式的引用。请将我指向 .NET 文档中的正确位置。
最佳答案
检查 following article
在 MSDN 上关于 N
格式的例子。这也包含在 Standard Numeric Format Strings
中。文章。
相关摘录:
// Formatting of 1054.32179:
// N: 1,054.32
// N0: 1,054
// N1: 1,054.3
// N2: 1,054.32
// N3: 1,054.322
When precision specifier controls the number of fractional digits in the result string, the result string reflects a number that is rounded to a representable result nearest to the infinitely precise result. If there are two equally near representable results:
- On the .NET Framework and .NET Core up to .NET Core 2.0, the runtime selects the result with the greater least significant digit (that is, using MidpointRounding.AwayFromZero).
- On .NET Core 2.1 and later, the runtime selects the result with an even least significant digit (that is, using MidpointRounding.ToEven).
关于c# - 什么是 ToString ("N0") 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16209509/