>>> "{0:0.1f}".format(45.34531)
'45.3'
a_float = 3.14159
formatted_float = "{:.2f}".format(a_float)
# 2.6 python and newer and python 3.x
# Put desired number of decimal by changing the number inside {:.2f} bellow;
print(' {:.2f}'.format(71.428571))
71.43
# 2.6 python and older
# Put desired number of decimal by changing the number inside '%.2f' bellow;
print('%.2f'%(71.428571))
71.43
>>> foobar = 3.141592
>>> print(f'My number is {foobar:.2f} - look at the nice rounding!')
My number is 3.14 - look at the nice rounding!
number = 3.333333
result = format(number, ".2g")
print("Formatted decimal number result is =>", result)
"Formatted decimal number result is => 3.33"
print "%.2f" % 5