[New-bugs-announce] [issue24403] Missing fixer for changed round() behavior

priska report at bugs.python.org
Sun Jun 7 12:58:41 CEST 2015

New submission from priska:

The behavior of the round() function has changed between Python 2.x and Python3.x. 

>From the release notes of Python 3.0: "The round() function rounding strategy and return type have changed. Exact halfway cases are now rounded to the nearest even result instead of away from zero. (For example, round(2.5) now returns 2 rather than 3.) round(x[, n]) now delegates to x.__round__([n]) instead of always returning a float. It generally returns an integer when called with a single argument and a value of the same type as x when called with two arguments."

2to3 conversion does not take this into account and thereby changes code behavior.

Suggested translations:

round(n) -> float(math.floor(n + math.copysign(0.5, n)))


round(n) -> float(math.trunc(n + math.copysign(0.5, n)))

components: 2to3 (2.x to 3.x conversion tool)
messages: 244951
nosy: priska
priority: normal
severity: normal
status: open
title: Missing fixer for changed round() behavior
type: behavior

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list