[issue1869] Builtin round function is sometimes inaccurate for floats
George Boutsioukis
report at bugs.python.org
Sat Jul 19 04:35:26 CEST 2008
George Boutsioukis <gboutsioukis at gmail.com> added the comment:
The issue is that the implementation of round includes multiplying the
number by 10**ndigits, thus unnecessarily losing some precision for
large numbers within the IEEE754 double limits. This means that even
smaller numbers can produce these results for higher ndigit values, eg.
>>> round(56294995342131.5, 3) #one less digit
56294995342131.508
In the submitted patch I used modf to split the number and keep the
integral intact.
----------
keywords: +patch
nosy: +gboutsioukis
Added file: http://bugs.python.org/file10944/round_patch.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1869>
_______________________________________
More information about the Python-bugs-list
mailing list