[Tutor] Precision with Decimal
gslindstrom at gmail.com
gslindstrom at gmail.com
Sun Feb 1 04:05:35 CET 2009
I am using the decimal module to work with money (US dollars and cents) and
do not understand the precision. The documentation states:
"The decimal module incorporates a notion of significant places so that
1.30 + 1.20 is 2.50. The trailing zero is kept to indicate significance.
This is the customary presentation for monetary applications."
But I get:
>>> from decimal import Decimal
>>> a = Decimal('1.25')
>>> a
Decimal('1.25')
>>> b = Decimal('2.50')
>>> b
Decimal('2.50')
>>> a+b
Decimal('3.8')
I expect (and would like) a+b to be '3.75'. I've read through the
getcontext() section but must be missing something. Can you help?
Thanks!
--greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090201/40d4f054/attachment.htm>
More information about the Tutor
mailing list