1num = 123.4567
2formatted_num = '{0:.2f}'.format(num) # to 2 decimal places
3# formatted_num = '123.46'
1print(format(432.456, ".2f"))
2
3>> 432.45
4
5print(format(321,".2f"))
6
7>> 321.00
1>>> x = 13.949999999999999999
2>>> x
313.95
4>>> g = float("{:.2f}".format(x))
5>>> g
613.95
7>>> x == g
8True
9>>> h = round(x, 2)
10>>> h
1113.95
12>>> x == h
13True
1numbers = [23.23, 0.123334987, 1, 4.223, 9887.2]
2
3for number in numbers:
4 print(f'{number:.4f}')
5