Tim Peters <t...@python.org> added the comment:

I'll add that the rounding mode is intended to ease emulating fixed-point 
arithmetic. The decimal spec claimed that was a goal, but there really isn't 
any direct support for saying, e.g., "I want two digits after the decimal 
point". Only for specifying total precision, independent of the radix point's 
position.

So, e.g., if you want to work with tax rates, etc, but keeping results to penny 
precision,

1. Set the rounding mode to ROUND_05UP with "plenty of" precision digits.

2. To add, say, a statutory 3.578% tax rate to an item with cost C:

       C *= decimal.Decimal("1.03578")
       C = C.quantize(decimal.Decimal(".01"), decimal.ROUND_HALF_UP)

or whatever final rounding mode local statutes require.

I"m not sure anyone other than Mike Cowlishaw realizes that, though ;-)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45918>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to