floating point woes

Ian Kelly ian.g.kelly at gmail.com
Tue Feb 15 19:09:11 EST 2011


On Tue, Feb 15, 2011 at 4:49 PM, Hans-Peter Jansen <hpj at urpla.net> wrote:
> Hi,
>
> while I usually cope with the woes of floating point issues, this is
> one, that I didn't expect:
>
>>>> round(2.385, 2)
> 2.3799999999999999
>
> Doesn't the docs say, it's rounded up for this case?
>
> <quote>
> 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
> </quote>
>
> Well, that one is clearly rounding down.
>
> What's up, eh, down here?

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 2.385
2.3849999999999998

Looks to me like it's working as expected...



More information about the Python-list mailing list