You can use format specifiers like
>>> "{:0>8.4f}".format(2.02) '002.0200' >>> print("{:0>8.4f}".format(2.02)) 002.0200 >>>
Here 8 represents the total width, .4 represents the accuracy. And 0> means the line should be right justified and filled to the left of 0 .
source share