is int(round(val)) safe?

Batista, Facundo FBatista at uniFON.com.ar
Tue Nov 23 11:57:57 EST 2004


[Mike Meyer]

#- It's much easier than that to get integer floating point numbers that
#- aren't correct. Consider:
#- 
#- >>> long(1e70)
#- 1000000000000000072531436381529235126158374409646521955518210
#- 1554790400L

You always can use Decimal:

>>> from decimal import *
>>> getcontext().prec = 80
>>> Decimal("1e70")
Decimal("1E+70")
>>> Decimal("1e70") + 1
Decimal("1000000000000000000000000000000000000000000000000000000000000000000
0001")
>>> long(Decimal("1e70"))
10000000000000000000000000000000000000000000000000000000000000000000000L

.	Facundo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041123/0de15ba0/attachment.html>


More information about the Python-list mailing list