Message407228
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 ;-) |
|
Date |
User |
Action |
Args |
2021-11-28 19:56:33 | tim.peters | set | recipients:
+ tim.peters, rhettinger, mark.dickinson |
2021-11-28 19:56:33 | tim.peters | set | messageid: <1638129393.16.0.781891026044.issue45918@roundup.psfhosted.org> |
2021-11-28 19:56:33 | tim.peters | link | issue45918 messages |
2021-11-28 19:56:33 | tim.peters | create | |
|