[英]How to add decimal separator to a grouped (money like) number?
Are {0:#,##}
and {0:#,#}
different? {0:#,##}
和{0:#,#}
不同? I know that the .
我知道.
determines the location of the decimal separator in the result string, and the ,
serves as both a group separator and a number scaling specifier. 确定结果字符串小数分隔符的位置,并且,
既作为分离器组和多个缩放说明符。 As a group separator, it inserts a localized group separator character between each group. 作为组分隔符,它在每个组之间插入一个本地化的组分隔符。 As a number scaling specifier, it divides a number by 1000 for each comma specified. 作为数字缩放说明符,它为指定的每个逗号将数字除以1000。
Take a look at some examples: 看一些例子:
original #,## #,#
12568 -> 12,568 12,568
12568.12 -> 12,568 12,568
1.12 -> 1 1
.12 -> Error Error
They are all the same even in error. 即使出错,它们都相同。
Why the decimal part does not appear in the examples? 为什么小数部分没有出现在示例中? How to add decimal separator to a grouped (money like) number? 如何将小数点分隔符添加到分组(类似于货币的数字)上?
See here: Custom Numeric Format Strings . 请参阅此处: 自定义数字格式字符串 。
The problem is in ,
. 问题出在,
。 Your culture decimal separator is .
您的文化小数点分隔符为.
, not ,
. 不,
。
If you replace ,
by .
如果替换,
按.
you will get: 你会得到:
original #.## #.#
12568 -> 12568 12568
12568.12 -> 12568.12 12568.1
1.12 -> 1.12 1.1
1.56 -> 1.56 1.6 //new (see rounding)
Also, you can pass needed IFormatProvider
that uses ,
as decimal separator and your example will work with ,
. 此外,您还可以通过所需IFormatProvider
使用,
如小数点分隔符和您的示例将工作,
。
So, the difference is visible in the last example - there can be rounding. 因此,差异在最后一个示例中可见-可以四舍五入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.