Q. How can you format a float with two decimals?

A
print('{:.2f}'.format(3.14159))
B
print('{2f}'.format(3.14159))
C
print('%.2f' % 3.14159)
D
Both A and C
Solution:

Both ‘{:.2f}’.format(3.14159) and ‘%.2f’ % 3.14159 output ‘3.14’.

Entri Contact Image

Get Expert Advice for Free: Register for Your Free Consultation Now!