gpt4 book ai didi

c# - 为什么百分比格式说明符乘以 100?

转载 作者:可可西里 更新时间:2023-11-01 02:59:20 25 4
gpt4 key购买 nike

为什么百分比的“p”字符串格式在使用百分号格式化之前将值乘以 100?

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#PFormatString

The Percent ("P") Format Specifier

The percent ("P") format specifier multiplies a number by 100 and converts it to a string that represents a percentage. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision supplied by the current PercentDecimalDigits property is used.

请问有什么方法可以防止在格式化之前数值乘以100?而不是做:

(value / 100).ToString("p")

最佳答案

至于原因,“百分比”的字面意思是“满分一百”,因此 50% 在数学上等同于 0.50。至于格式,为什么不直接加一个百分号呢?

value + "%"

...或类似这样的内容:

value.ToString("#.00\\%")

关于c# - 为什么百分比格式说明符乘以 100?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8131861/

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