2.6.1 - simple division

Tim Rowe digitig at gmail.com
Mon Mar 9 20:12:06 CET 2009

2009/3/8  <farsight at gmail.com>:
>>>> 4 / 5.0
> 0.800000000000000004
>>>> 0.8 * 5
> 4.0
> python 2.6.1 on mac. What the hell is going on here?

I know this has already been answered in detail, but one thing that
it's easy for those new to floating point issues to miss is that
fractions that can be expressed exactly in decimal can end up as
recurring decimals in binary. 0.8 looks nice and tidy, but in binary
(if I get this right) it's 0.1100110011001100..., recurring ad
infinitum. The computer has to truncate it somewhere.

Tim Rowe

More information about the Python-list mailing list