decimal and trunkating

Peter Hansen peter at engcorp.com
Thu Jun 2 15:50:21 CEST 2005


Peter Hansen wrote:
>  >>> d = decimal.Decimal('199.999')
>  >>> decimal.getcontext().rounding = decimal.ROUND_FLOOR
>  >>> d.quantize(decimal.Decimal('1.00'))
> Decimal("199.99")

Or skip changing the context and use the second argument to quantize:

d.quantize(Decimal('1.00'), decimal.ROUND_FLOOR)

-Peter



More information about the Python-list mailing list