Python Forum
Small help with formatting - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Small help with formatting (/thread-8975.html)



Small help with formatting - Fumi - Mar-15-2018

Does anyone know how to make this all appear in one sentence?

print "You need to save £{0:.2f} each month.".format(finance)
print "To reach the target of £{0:.2f}.".format(cost)
I tried this but it just gives the same value in both positions.

print "You need to save £{0:.2f} each month to reach the target of £{0:.2f}".format(finance,cost)
I'm pulling my hair out. Well, what's left of it. Smile

I found it. Thanks anyway.

I found it. Thanks anyway. The first number controls the position.


RE: Small help with formatting - snippsat - Mar-15-2018

You should also stop using Python 2 and switch to Python 3.
The can use cooler stuff like f-string Cool
>>> cost = 99.75999
>>> finance = 50000
>>> print(f"You need to save £{cost:.2f} each month to reach the target of £{finance:.2f}")
You need to save £99.76 each month to reach the target of £50000.00