How do I get my decimals to stay at 2 places for representing money using the decimal module?
decimal
I\'ve setting the precision, and damn near everything else
>>> decimal.getcontext().prec = 2 >>> d = decimal.Decimal('2.40') >>> d/17 Decimal('0.14')
You just have to set the precision to 2 (the first line) and them everything will use no more than 2 decimal places
Just for comparison:
>>> 2.4 / 17 0.1411764705882353