[Numpy-discussion] Integer cast problems

Ralph Kube ralphkube@googlemail....
Fri Feb 13 11:22:21 CST 2009


Thanks alot people, my problem is gone now.

Keith Goodman skrev:
> On Thu, Feb 12, 2009 at 9:21 AM, Ralph Kube <ralphkube@googlemail.com> wrote:
>> The same happens on the ipython prompt:
>>
>> 0.145 * 0.005 = 28.999999999999996
>> N.int32(0.145 * 0.005) = 28
>>
>> Any ideas how to deal with this?
> 
> Do you want the answer to be 29? N.int32 truncates. If you want to
> round instead, you could use that standard trick of adding 0.5:
> 
>>> np.int32(0.5 + 0.145 / 0.005)
>    29
> 
> or
> 
>>> np.round(0.145 / 0.005)
>    29.0
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list