2.6.1 - simple division

koranthala koranthala at gmail.com
Sun Mar 8 10:43:03 EDT 2009


On Mar 8, 7:22 pm, farsi... at gmail.com wrote:
> On Mar 8, 2:16 pm, farsi... at gmail.com wrote:
>
> > >>> 4 / 5.0
>
> > 0.800000000000000004>>> 0.8 * 5
>
> > 4.0
>
> > python 2.6.1 on mac. What the hell is going on here?
>
> Pure curiosity prompted me to try the following:>>> 40 / 5.0
>
> 8.0
>
> Strange...

Please see http://docs.python.org/library/decimal.html for explanation
of why this happens.
To get the proper values, try
>>> Decimal(4)/Decimal("5.0")
Decimal("0.8")



More information about the Python-list mailing list