I'm trying to format Decimal
s without trailing zeros. Decimal.normalize()
gets me most of the way there, but any value that's a multiple of 10 is converted to engineering notation. E.g.,
>>> import decimal
>>> for number in map(decimal.Decimal, ['0.00', '0.25', '0.50', '1.00', '5.00', '10.00', '15.00', '20.00']):
... print(number.normalize())
0
0.25
0.5
1
5
1E+1 # Should be `10`.
15
2E+1 # Should be `20`.
Is there some context option to disable engineering notation for .normalize()
, or a different formatting method that I'm missing?