This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Document 2.x -> 3.x round changes in "What's New" documents.
Type: Stage: resolved
Components: Documentation Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: georg.brandl, mark.dickinson
Priority: low Keywords: patch

Created on 2009-11-04 10:33 by mark.dickinson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
issue7261.patch mark.dickinson, 2010-06-12 17:06
Messages (3)
msg94886 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-11-04 10:33
The round builtin function changed in three fairly significant ways
between 2.x and 3.x:

(1) In 2.x, halfway cases are rounded using the
    round-half-away-from-zero rule, while in 3.x they're
    rounded using round-half-to-even.

(2) The single argument version, round(x), generally returns an
    integer in 3.x and a float in 2.x.  (For float inputs, this
    actually changed between 3.0 and 3.1, not between 2.x and 3.x.).

(3) In 3.x, round(x, n) delegates to x.__round__; in 2.x, x is simply
    converted to a float (if possible).  (So for example, rounding
    a Decimal instance in 2.x gives a float result;  in 3.x it uses
    Decimal.__round__, which returns another Decimal.)

I think all of this is covered (more-or-less) in the 'built-in
functions' section of the documentation, but I suggest that it would be
worth putting an entry for these changes into the 'What's new in Python
3.0' document as well.

The first change above is particularly evil (i.e., likely to cause
late-discovered bugs), since the value of round(x) will change silently,
just for a few values of x.  Note that this change affects
integers, too, so it's applicable beyond the "well you should be
using Decimal then" situations.

>>> int(round(2500, -3))

>>> round(2500, -3)
msg107673 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 17:06
Here's a patch.
msg108040 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-17 18:26
Applied in r82051 (py3k) and r82052 (release31-maint).
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51510
2010-06-17 18:26:27mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg108040

stage: commit review -> resolved
2010-06-12 17:07:13mark.dickinsonsetstage: needs patch -> commit review
2010-06-12 17:06:48mark.dickinsonsetfiles: + issue7261.patch
keywords: + patch
messages: + msg107673
2009-11-15 13:51:06mark.dickinsonsetpriority: low
2009-11-04 11:03:49mark.dickinsonsetassignee: georg.brandl -> mark.dickinson
2009-11-04 10:35:51mark.dickinsonsettitle: Document 2.x -> 3.x round changes in "Whats New" documents. -> Document 2.x -> 3.x round changes in "What's New" documents.
2009-11-04 10:33:04mark.dickinsoncreate