format - python padding decimals with zeros -


i'm looking way pad float decimals zeros:

this 1 reference:

in [37]: '{:5.5}'.format(round(4.123456, 5)) out[37]: '4.1235' 

i have this:

in [38]: '{:5.5}'.format(4.1) out[38]: '  4.1' 

but have this:

out[38]: '4.1000' 

for formatting floating point numbers should use "f" specifier:

>>> '{:f}'.format(4.1) '4.100000' 

now ":5.5f" uses 5 decimal places , pads complete output @ least 5 characters, doesn't make sense. specify precision only:

>>> '{:.4f}'.format(4.1) '4.1000' 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -