X Tutup
The Wayback Machine - https://web.archive.org/web/20250609190455/https://github.com/python/cpython/issues/96564
Skip to content

Builtin round is imprecise is certain cases #96564

Closed as not planned
Closed as not planned
@TheSilvered

Description

@TheSilvered

Bug report

The round function does not round even numbers correctly. When an even number ends with .5 it gets rounded down instead of up, unlike odd numbers. This happens to negative numbers too. Providing a second argument of 0 does not change the outcome.

>>> round(0.5)  # expecting 1
0
>>> round(0.5, 0)  # expecting 1.0
0.0
>>> round(1.5)  #correctly rounds to 2
2
>>> round(2.5)  #expecting 3
2
>>> round(-2.5) #expecting -3
-2

Your environment

  • CPython versions tested on: 3.10.6, x64
  • Operating system and architecture: Windows 11 build 22622.590 64 bit

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup