I want to replace the old string formatting behavior with the new python string formatting syntax in my scripts, but how to avoid rounding when working with float?
Old version
print ('%02d:%02d:%02d' % (0.0,0.9,67.5))
gives 00:00:67
while my (obviously wrong) translation into the new syntax
print ('{0:0>2.0f}:{1:0>2.0f}:{2:0>2.0f}'.format(0.0,0.9,67.5))
gives 00:01:68.
How to avoid rounding here and get old output with new format syntax?
source
share