为什么百分比格式说明符乘以 100? [英] Why does percentage format specifier multiply by 100?

查看:49
本文介绍了为什么百分比格式说明符乘以 100?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why does the 'p' string format for percent multiply the value by 100 before formatting it with the percentage sign?

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

百分比(P")格式说明符

百分比(P")格式说明符将数字乘以 100 和将其转换为表示百分比的字符串. 精度说明符指示所需的小数位数.如果省略精度说明符,提供默认数值精度使用当前 PercentDecimalDigits 属性.

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?而不是做:

Is there any way to prevent the value from being multiplied by 100 before formatting? Rather than doing:

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

推荐答案

至于 why,percent"的字面意思是100%",所以 50% 在数学上等同于 0.50.至于格式,为什么不加个百分号?

As to the why, "percent" literally means "out of one hundred", so 50% is mathematically equivalent to 0.50. As to formatting, why not just add a percent sign?

value + "%"

...或类似的东西:

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

这篇关于为什么百分比格式说明符乘以 100?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆