I know how to control the number of decimals, but how do I control the number of zeros specifically?
For example:
104.06250000 -> 104.0625
119.00000 -> 119.0
72.000000 -> 72.0
I know how to control the number of decimals, but how do I control the number of zeros specifically?
For example:
104.06250000 -> 104.0625
119.00000 -> 119.0
72.000000 -> 72.0
How about using the decimal module?
From the documentation:
"The decimal module incorporates a notion of significant places so that 1.30 + 1.20 is 2.50. The trailing zero is kept to indicate significance. This is the customary presentation for monetary applications. For multiplication, the “schoolbook” approach uses all the figures in the multiplicands. For instance, 1.3 * 1.2 gives 1.56 while 1.30 * 1.20 gives 1.5600."
The normalize() function removes trailing zeros:
>>> from decimal import *
>>> d1 = Decimal("1.30")
>>> d2 = Decimal("1.20")
>>> d3
Decimal("1.5600")
>>> d3.normalize()
Decimal("1.56")