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.

classification
Title: round() gives wrong result
Type: behavior Stage: resolved
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dechamps, steven.daprano, veky
Priority: normal Keywords:

Created on 2021-07-10 05:27 by dechamps, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg397238 - (view) Author: Jos Dechamps (dechamps) Date: 2021-07-10 05:27
round(0.3368655,6) returns 0.336865 instead of 0.336866
msg397239 - (view) Author: Vedran Čačić (veky) * Date: 2021-07-10 05:30
Have you seen the Note at https://docs.python.org/3/library/functions.html?highlight=Note#round?
msg397241 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-07-10 06:36
Not a bug, the result is correct.

Python floats are binary floating point values, not decimal. 0.3368655's actual value is exactly:

0.336865499999999984392928809029399417340755462646484375

so when rounding to six decimal places, the seventh decimal place is a four, not five, and it rounds down to 0.336865. To be precise, it rounds down to:

0.336865000000000025526247782181599177420139312744140625
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88761
2021-07-10 06:36:58steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg397241

resolution: not a bug
stage: resolved
2021-07-10 05:30:38vekysetnosy: + veky
messages: + msg397239
2021-07-10 05:27:56dechampscreate