How to have negative zero always formatted as positive zero in a python string?

Add zero:

>>> a = -0.0
>>> a + 0
0.0

which you can format:

>>> '{0:.3f}'.format(a + 0)
'0.000'

Leave a Comment