简体   繁体   English

为什么Math.Round(106.8,2,MidpointRounding.AwayFromZero)返回106.8而不是106.80?

[英]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.8d106.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.

相关问题 JavaScript中的Math.round MidPointRounding.AwayFromZero - Math.round MidPointRounding.AwayFromZero in javascript 使用Math.Round和MidpointRounding.AwayFromZero四舍五入一个数字 - Round a number using Math.Round with MidpointRounding.AwayFromZero Math.Round bug 81.725 MidpointRounding.AwayFromZero = 81.72 - Math.Round bug 81.725 MidpointRounding.AwayFromZero = 81.72 与Delphi中的MidpointRounding.AwayFromZero相当的Math.Round()是什么? - What is the equivalent of Math.Round() with MidpointRounding.AwayFromZero in Delphi? 如何使用NET Math.Round( <decimal> , <int> ,MidpointRounding.AwayFromZero) - How to round off correctly with NET Math.Round(<decimal>,<int>,MidpointRounding.AwayFromZero) 使用Math.Round(ReportItems!category.Value,MidpointRounding.AwayFromZero)返回不正确的值 - Using Math.Round(ReportItems!category.Value,MidpointRounding.AwayFromZero) returns incorrect value .NET Math.Round(<double>,<int>,MidpointRounding.AwayFromZero)无法正常工作 - .NET Math.Round(<double>,<int>,MidpointRounding.AwayFromZero) not working correctly 中点舍入为零 - MidpointRounding.AwayFromZero 为什么MidpointRounding.AwayFromZero和MidpointRounding.ToEven做同样的事情? - Why does MidpointRounding.AwayFromZero and MidpointRounding.ToEven do the same thing? 为什么System.MidpointRounding.AwayFromZero在这个实例中没有向上舍入? - Why does System.MidpointRounding.AwayFromZero not round up in this instance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM