I have a float let say 8.8 and I want to format it into 0008.800
I read this http://docs.python.org/2/library/stdtypes.html#string-formatting
If I do
'%06g'%(8.8)
I get 0008.8
but I still don't know how to include the other decimals
I have a float let say 8.8 and I want to format it into 0008.800
I read this http://docs.python.org/2/library/stdtypes.html#string-formatting
If I do
'%06g'%(8.8)
I get 0008.8
but I still don't know how to include the other decimals
Use %f not %g:
>>> '%08.3f'%(8.8)
'0008.800'
Where 8 is the width and 3 is the precision.
With new style string formatting:
>>> "{:08.3f}".format(8.8)
'0008.800'