How to display a float with two decimal places?

Solution 1:

Since this post might be here for a while, lets also point out python 3 syntax:

"{:.2f}".format(5)

Solution 2:

You could use the string formatting operator for that:

>>> '%.2f' % 1.234
'1.23'
>>> '%.2f' % 5.0
'5.00'

The result of the operator is a string, so you can store it in a variable, print etc.