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
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to