This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients mark.dickinson, rhettinger, tim.peters
Date 2021-11-28.19:56:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638129393.16.0.781891026044.issue45918@roundup.psfhosted.org>
In-reply-to
Content
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 ;-)
History
Date User Action Args
2021-11-28 19:56:33tim.peterssetrecipients: + tim.peters, rhettinger, mark.dickinson
2021-11-28 19:56:33tim.peterssetmessageid: <1638129393.16.0.781891026044.issue45918@roundup.psfhosted.org>
2021-11-28 19:56:33tim.peterslinkissue45918 messages
2021-11-28 19:56:33tim.peterscreate