how to convert an integer to a float?
Farshid Lashkari
no at spam.com
Tue Feb 27 19:15:14 EST 2007
yinglcs at gmail.com wrote:
> Hi, I have the following functions, but ' dx = abs(i2 - i1)/min(i2,
> i1)' always return 0, can you please tell me how can i convert it from
> an integer to float?
When two integers are involved in a division, the result will also be a
division. If one of the operands is a float, then the result will be a
float instead. So try casting one of the values to a float before
performing the division:
dx = float(abs(i2 - i1))/min(i2, i1)
-Farshid
More information about the Python-list
mailing list