format float numbers : float format « Data Type « Python Tutorial






import math
for eachNum in (.2, .7, 1.2, 1.7, -.2, -.7, -1.2, -1.7):
    print "int(%.1f)\t%+.1f" % (eachNum, float(int(eachNum)))
    print "floor(%.1f)\t%+.1f" % (eachNum, math.floor(eachNum))
    print "round(%.1f)\t%+.1f" % (eachNum, round(eachNum))
    print '-' * 20








2.5.float format
2.5.1.formatting float number, use the f specifier and supply the precision as a . (dot) followed by the number of decimals
2.5.2.Formatting Numbers
2.5.3.Floating Point and Exponential Notation Output
2.5.4.format float numbers