num = 123.4567
formatted_num = '{0:.2f}'.format(num) # to 2 decimal places
# formatted_num = '123.46'
print(format(432.456, ".2f"))
>> 432.45
print(format(321,".2f"))
>> 321.00
print ("{0:.2f}".format(a))
# 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
formatted_float = "{:.2f}".format(a_float)
num = 123.4567
print(round(num, 2))
#2 is the number of decimal digits (after the .)
>>> 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!
print("{0:.2f}".format(sum(query_marks)/len(query_marks)))
# this will print up to digits after decimal
print("%.2f" % (70/105))
print(round(a, 2))
print "%.2f" % 5