Python, want to print float in exact format +-00.00

后端 未结 3 1664
花落未央
花落未央 2020-12-20 14:55

I need to format a float to the format +-00.00, tried the basic string formatting but can\'t get the leading + or - sign or two leading 0s if the value is fractional, any po

3条回答
  •  时光说笑
    2020-12-20 15:19

    '%+06.2f' % 1.1123344

    + means always use sign
    0 means zero fill to full width.
    6 is the total field width including sign and decimal point
    .2 means 2 decimals.
    f is float
    

提交回复
热议问题