1# test float formatting 2 3# general rounding 4for val in (116, 1111, 1234, 5010, 11111): 5 print("%.0f" % val) 6 print("%.1f" % val) 7 print("%.3f" % val) 8 9# make sure rounding is done at the correct precision 10for prec in range(8): 11 print(("%%.%df" % prec) % 6e-5) 12 13# check certain cases that had a digit value of 10 render as a ":" character 14print("%.2e" % float("9" * 51 + "e-39")) 15print("%.2e" % float("9" * 40 + "e-21")) 16 17# check a case that would render negative digit values, eg ")" characters 18# the string is converted back to a float to check for no illegal characters 19float("%.23e" % 1e-80) 20