I think a problem occured when i used long()

Jeff Epler jepler at unpythonic.net
Wed Sep 1 16:03:58 EDT 2004


"long" only represents integers, not numbers with a fractional part.
long(f) when f is a float discards the fraction.

    >>> long(-.999)
    0L
    >>> long(.999)
    0L

The Decimal module, which will be in 2.4, can exactly represent numbers
with decimal fractions. 

    >>> decimal.Decimal("5.07e-25")
    Decimal("5.07E-25")
    >>> 5.07e-25 + 1 - 1
    0.0
    >>> decimal.Decimal("5.07e-25") + 1 - 1
    Decimal("5.07E-25")

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040901/fb149cc9/attachment.sig>


More information about the Python-list mailing list