Python舍入函数返回不同的答案

如果我进行舍入(4.265,2),则返回4.26,但是如果我进行舍入(4.375,2),则返回4.38。

round(4.265,2)
round(4.375,2)
Answer:
4.26 (Expecting 4.27 instead of 4.26)
4.38

我期望第一轮函数的输出为4.27,就像第二轮函数的输出(4.38)一样。有谁知道为什么python返回不同的舍入答案?

candy009 回答:Python舍入函数返回不同的答案

Python使用“四舍五入到最接近,关系到偶数的舍入”方法。 https://en.wikipedia.org/wiki/IEEE_754-1985#Rounding_floating-point_numbers

本文链接:https://www.f2er.com/3163686.html

大家都在问