Can see the first article: cloud.tencent.com/developer/a… But because I have python2 here, python3 here

And then we find the difference between 2 and 3


First, float 2,3 all follow HALF_ROUND_EVEN

Decimal for 3 follows HALF_ROUND_UP, but not for 2. Finally find a way

price = (decimal.Decimal(str('12.35')) / 100).quantize(decimal.Decimal('01'), decimal.ROUND_HALF_UP)Copy the code

To use decimal’s quantize method, round or context is useless