0

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

1 Answer 1

2

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.