I'm trying to use Decimal.quantize()
to achieve the following: -
For any amount of money, expressed as a python decimal of default precision, I want to round it using decimal.ROUND_HALF_UP
so that it has no cents after rounding.
For example, given 1.25, I'm trying to obtain 1.00 (signifying no cents)
given 1.49 I'm trying to obtain 1.00
given 1.50 I'm trying to obtain 2.00
given 1.87 I'm trying to obtain 2.00
given 2.00 I'm trying to obtain 2.00
So there are two ranges for the cents -- 0 cent to 49 cents; and 50 cents to 99 cents. For cents upto 49, I want to round down, for cents 50 and up I want to round up. I'm trying to obtain the result with two significant decimal places (which will always be 00).
I don't have any negative values to deal with here. How do I round my dollars to get the amount I want? Also is there any other option other than quantize
?