floating point woes
anikom15 at gmail.com
Wed Feb 16 01:05:39 CET 2011
On Wed, 2011-02-16 at 00:49 +0100, Hans-Peter Jansen wrote:
> while I usually cope with the woes of floating point issues, this is
> one, that I didn't expect:
> >>> round(2.385, 2)
> Doesn't the docs say, it's rounded up for this case?
> Values are rounded to the closest multiple of 10 to the power minus n;
> if two multiples are equally close, rounding is done away from 0
> Well, that one is clearly rounding down.
> What's up, eh, down here?
> Python 2.6 (r26:66714, Feb 8 2011, 08:50:11)
> [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
It's actually rounding up, but 2.38 cannot be represented precisely by
floating points. This was fixed in Python 3.1.
More information about the Python-list