[英]Why does Math.Round(106.8, 2, MidpointRounding.AwayFromZero) return 106.8 and not 106.80?
I need the number returned to have exactly 2 decimal points but I can't seem to get this to work. 我需要返回的数字必须精确地有2个小数点,但是我似乎无法正常工作。
Is this something built into C#
? 这是
C#
内置的东西吗?
I also tried setting the number to a double and a decimal and I get the same answer both times. 我还尝试将数字设置为双精度和十进制,两次都得到相同的答案。
price = Math.Round(106.8, 2, MidpointRounding.AwayFromZero);
Floating-point values 106.8d
and 106.80d
are totally the same. 浮点值
106.8d
和106.80d
完全相同。 Use .ToString()
or string.Format()
to represent them as strings with desired formatting. 使用
.ToString()
或string.Format()
将它们表示为具有所需格式的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.