On 2007-03-05, Andrew Koenig <[EMAIL PROTECTED]> wrote:
><[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> 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?
>
> I don't think that's what you really want to do.
>
> What you really want is for dx to be a float rather than being truncated to 
> an integer.  Division is going to behave that way in the future, so if you 
> want it to behave that way now, you can write
>
>     from __future__ import division
>
> at the beginning of your program.
>
> If for some reason you don't want to rely on using a version of Python that 
> knows about this future behavior, you might consider
>
>     dx = float(abs(i2 - i1))/min(i2, i1)

I prefer to multiply by 1.0 That has the advantage it continues to work
if your numbers happen to be complex.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to