A
Anthony
Isn't this a mistake???
3499.4000000000001
My Python 2.5.1 spat that out..
3499.4000000000001
My Python 2.5.1 spat that out..
Isn't this a mistake???
Anthony said:Isn't this a mistake???
3499.4000000000001
My Python 2.5.1 spat that out..
No, round() return binary floats that, in general, cannot represent
decimal floats exactly. Formatted printing gives what you expect.
>>> '%8.2f' % x
' 3499.35'
Which 'this'? That is, what were you expecting?
If you're objecting to the fact that the second result
produces 3499.3499999999999 instead of 3499.35, then
no, that's not a mistake; see
http://www.python.org/doc/faq/general/#why-are-floating-point-calcula...
for more information. But I'm guessing that you're
questioning the fact that a value that's apparently
*less* than 3499.35 is rounded up to 3499.4, rather
than down to 3499.3. ?
False
Then yes, I'd agree that's less than ideal, though I
don't consider it a particularly serious bug.
It's been on my list of things to fix for a while.
"apparently" being the operative word.
Well, it's not just an apparent problem: the closest
floating-point number to 3499.35 really *is* less than
3499.35.
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.