Working with decimal points
mtallen at gmail.com
mtallen at gmail.com
Sat Apr 8 11:30:50 EDT 2006
Byte wrote:
> How come:
>
> sum = 1/4
> print sum
>
> returns 0? 1/4=0.25, not 0. How do I fix this?
Make sure there is at least one float in your equation. In your example
Python is doing interger math for you and returing the floor. You need
to give it a hint that you would like to do floating point math.
>>> sum = 1.0/4
>>> print sum
0.25
>>> sum = 1/4.0
>>> print sum
0.25
>>>
More information about the Python-list
mailing list