远离零的四舍五入给出不正确的结果

问题描述 投票:0回答:0

https://dotnetfiddle.net/jHW5QR

我有两个数字四舍五入到小数点后第二位

Console.WriteLine(Math.Round(74.945, 2, MidpointRounding.AwayFromZero));
Console.WriteLine(Math.Round(33.435, 2, MidpointRounding.AwayFromZero));

第一次我得到

74.94
,而我应该得到
74.95
。第二个给了我
33.44
的正确结果。

如果我使用 calculator soup 并选择 method

Round Half Away from Zero
对应于
MidpointRound.AwayFromZero
然后我得到 74.95。因此,我为 Round 选项输入 74.945,为
To
选项输入 hundredths (2 decimal, cents)

我很茫然,我做错了什么?

c# .net rounding
© www.soinside.com 2019 - 2024. All rights reserved.