小编Ale*_*per的帖子

Python3舍入到最近的偶数

Python3.4舍入到最近的偶数(在打破平局情况下).

>>> round(1.5)
2
>>> round(2.5)
2
Run Code Online (Sandbox Code Playgroud)

但是当四舍五入到整数时,它似乎只是这样做.

>>> round(2.75, 1)
2.8
>>> round(2.85, 1)
2.9
Run Code Online (Sandbox Code Playgroud)

在上面的最后一个例子中,当圆整到最接近的偶数时,我会预期2.8作为答案.

为什么两种行为之间存在差异?

python floating-point rounding python-3.x

17
推荐指数
1
解决办法
2801
查看次数

标签 统计

floating-point ×1

python ×1

python-3.x ×1

rounding ×1