floating point woes

H

Hans-Peter Jansen

Hi,

while I usually cope with the woes of floating point issues, this is
one, that I didn't expect:
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?

Pete

Python 2.6 (r26:66714, Feb 8 2011, 08:50:11)
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
 
M

Mel

Hans-Peter Jansen said:
Hi,

while I usually cope with the woes of floating point issues, this is
one, that I didn't expect:

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?

2.385 isn't really 2.385:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
so it correctly rounded down. You need to use Decimal numbers if you want
numbers that behave the way they look.

Mel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top