0

How to change the data format in f.write function?

loaded_data = 349.00 or 3.00

I want to change data format in write function like %6f in print function.

ex) 349.00 -> 349.000000 , 3.00 -> 3.000000

f = open("test.txt", 'w')
f.write( str.(loaded_data).zfill(?) )  

What is the code that performs above function?

1 Answer 1

2

you can use:

>>> loaded_data = 349.00
>>> str.format('{0:.6f}', loaded_data)
'349.000000'

or

>>> loaded_data = 349.00
>>> "%.6f" % loaded_data
'349.000000'
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.