New submission from Olli <mrblueskie...@gmail.com>:

When rounding numbers with round(), middle values at with even base number are 
rounded in wrong direction.

Python 3.9.1 (default, Feb  3 2021, 07:38:02) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin

MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
macOS 11.2.3 (20D91), Darwin 20.3.0

to reproduce (wrong results marked with "*"):

floats:

>>> for i in range(0, 10):
...     i /= 2
...     print(i, '->', round(i))
... 
0.0 -> 0
0.5 -> 0 *
1.0 -> 1
1.5 -> 2
2.0 -> 2
2.5 -> 2 *
3.0 -> 3
3.5 -> 4
4.0 -> 4
4.5 -> 4 *

and for ints:

>>> for i in range(50, 1000, 50):
...     print(i, '->', round(int(i), -2))
... 
50 -> 0 *
100 -> 100
150 -> 200
200 -> 200
250 -> 200 *
300 -> 300
350 -> 400
400 -> 400
450 -> 400 *
500 -> 500
550 -> 600
600 -> 600
650 -> 600 *
700 -> 700
750 -> 800
800 -> 800
850 -> 800 *
900 -> 900
950 -> 1000

----------
components: Library (Lib)
messages: 391499
nosy: MrBlueSkies
priority: normal
severity: normal
status: open
title: round() produces incorrect results with certain values
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43903>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to