If you need to track the number of significant digits past the decimal, neither float
nor int
is the correct way to store your number. Instead, use Decimal
:
from decimal import Decimal
a = Decimal('0.00')
print(str(a))
...emits exactly 0.00
.
If doing this, you should probably also read the question Significant figures in the decimal module, and honor the accepted answer's advice.
Of course, you can also round to a float or an int, and then reformat to the desired number of places:
a = float('0.00')
print('%.2f' % a) # for compatibility with ancient Python
print('{:.2f}'.format(a)) # for compatibility with modern Python
print(f"{a:.2f}") # for compatibility with *very* modern Python