Precision?

Jeff Epler jepler at unpythonic.net
Sun May 15 17:23:16 EDT 2005


If you want to do decimal arithmetic, use the decimal module which is
new in Python 2.4.

Python 2.4 (#1, Jan 22 2005, 20:45:18) 
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal as D
>>> D("1.0") + D("3.0") + D("4.6")
Decimal("8.6")
>>> 

when you write '4.6', you get a binary floating-point number which is
not equal to the decimal number 4.6.
>>> 4.6
4.5999999999999996
>>> 4.6 == D("4.6")
False

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/20050515/7ff0d497/attachment.sig>


More information about the Python-list mailing list