how to print a float to 2 decimal places

A

Abel Tefera

Guest
I want number from input to print out with 2 decimal places. You can assume that the number will always be a float.

num = 20.0


Desired output - 20.00.

I've tried this code:

num = round(num, 2)
num = float('{0.2f}'.format(num))
print(num)

Continue reading...
 
Top