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>>> foobar = 3.141592
2>>> print(f'My number is {foobar:.2f} - look at the nice rounding!')
3
4My number is 3.14 - look at the nice rounding!
5