Working with decimal points
Peter Hansen
peter at engcorp.com
Sat Apr 8 11:47:20 EDT 2006
Byte wrote:
> That dosnt work either:
>
> sum = 0.1+1/4
> print sum
>
> Just returns 0.1
That's because the 1/4 is executed first, and the problem mentioned
still applies (i.e. you get a 0, then add it to 0.1).
The best fix for you might be simply to place this line at the start
(before all other code) of your module:
from __future__ import division
That will change the way simple division works to give you the results
you expected. See the online docs for more background on this.
-Peter
More information about the Python-list
mailing list