Format a number containing a decimal point with leading zeroes

前端 未结 5 1227
南旧
南旧 2021-02-20 04:48

I want to format a number with a decimal point in it with leading zeros.

This

>>> \'3.3\'.zfill(5)
003.3

considers all the dig

5条回答
  •  广开言路
    2021-02-20 05:09

    print('{0:07.3f}'.format(12.34))
    

    This will have total 7 characters including 3 decimal points, ie. "012.340"

提交回复
热议问题