Possible Duplicate:
Display a float with two decimal places in Python
How can I force all numbers in python to output two decimal places after them?
E.G.
0.5 should be 0.50
Possible Duplicate:
Display a float with two decimal places in Python
How can I force all numbers in python to output two decimal places after them?
E.G.
0.5 should be 0.50
The format mini language is preferred these days (since the %
format operator may be deprecated one day.):
>>> print '{:.2f}'.format(.5)
0.50
Plus, IMHO, string.format() is easier to read.
To print numbers:
print "%.2f" %num
To store numbers in variables:
round(num, 2)