I think a problem occured when i used long()

Jorge Godoy godoy at ieee.org
Wed Sep 1 15:11:04 EDT 2004


alikakakhel3 at hotmail.com (Ali) writes:

> I did the folloing in python shell:
>
>>>> x = 5.07e-25
>>>> x = long(x)
>>>> print x
> 0L
>
> Um... I was under the impresion that long numbers had very very long
> precision. But, it seems that in this case it rounded it to zero :(
>
> Please Help. Thank you :)

Isn't "long" a long integer? ;-)


>>> help(long)

class long(object)
 |  long(x[, base]) -> integer
 |
 |  Convert a string or number to a long integer, if possible.  A floating
 |  point argument will be truncated towards zero (this does not include a
 |  string representation of a floating point number!)  When converting a
 |  string, use the optional base.  It is an error to supply a base when
 |  converting a non-string.

(...)


So, converting a float to an integer should really truncate the result,
as is in the documentation.


Sds,
-- 
Godoy.     <godoy at ieee.org>



More information about the Python-list mailing list