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

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -