How to print 2 decimal places in Python

Printing a float with two decimal places outputs the float with two digits after the decimal point. For example, printing 2.34212 with two decimal places results in 2.34.
There are many ways to set the precision of floating-point value. Some of them are
discussed below. We can use % operator
, format()
and round()
num = 2.34164 #using % print('%.2f'%num) #using format() print('{0:.2f}'.format(num)) #using round() print(round(num, 2))
Output:
2.34 2.34 2.34
Subscribe
Login
Please login to comment
0 Discussion