[Numpy-discussion] Integer cast problems
Ralph Kube
ralphkube at googlemail.com
Fri Feb 13 12:22:21 EST 2009
Thanks alot people, my problem is gone now.
Keith Goodman skrev:
> On Thu, Feb 12, 2009 at 9:21 AM, Ralph Kube <ralphkube at 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 at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list