[issue46467] Rounding 5, 50, 500 behaves differently depending on preceding value

2022-01-21 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

As documented, this is not a bug.

"if two multiples are equally close, rounding is done toward the even choice"

https://docs.python.org/3/library/functions.html#round

This is also called "Banker's Rounding" or "Round half to even" and for 
rounding many values, it minimizes the expected total rounding error.

https://en.wikipedia.org/wiki/Rounding#Round_half_to_even

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46467] Rounding 5, 50, 500 behaves differently depending on preceding value

2022-01-21 Thread Spencer Brown


Spencer Brown  added the comment:

This is intentional behaviour, if the value is 5 it rounds towards even as 
documented here: https://docs.python.org/3/library/functions.html#round
The reason is so that if you have a bunch of random data, rounding won't 
slightly bias the result upward or downward.

--
nosy: +Spencer Brown

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46467] Rounding 5, 50, 500 behaves differently depending on preceding value

2022-01-21 Thread Adam Ulrich


New submission from Adam Ulrich :

round(250,-2) returns 200
round(350,-2) returns 400
round(450,-2) returns 400
round(550,-2) returns 600
round(5,-1) returns 0
round(15,-1) returns 20
round(500,-3) returns 0
round(1500,-3) returns 2000

expected: round of 5 to consistently rounds up.

--
components: Interpreter Core
messages: 411222
nosy: adam.ulrich
priority: normal
severity: normal
status: open
title: Rounding 5,50,500 behaves differently depending on preceding value
type: behavior
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com