1def test(fmt, *args): 2 print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<") 3 4 5test("{:10.4}", 123.456) 6test("{:10.4e}", 123.456) 7test("{:10.4e}", -123.456) 8# test("{:10.4f}", 123.456) 9# test("{:10.4f}", -123.456) 10test("{:10.4g}", 123.456) 11test("{:10.4g}", -123.456) 12test("{:10.4n}", 123.456) 13test("{:e}", 100) 14test("{:f}", 200) 15test("{:g}", 300) 16 17test("{:10.4E}", 123.456) 18test("{:10.4E}", -123.456) 19# test("{:10.4F}", 123.456) 20# test("{:10.4F}", -123.456) 21test("{:10.4G}", 123.456) 22test("{:10.4G}", -123.456) 23 24test("{:06e}", float("inf")) 25test("{:06e}", float("-inf")) 26test("{:06e}", float("nan")) 27 28# The following fails right now 29# test("{:10.1}", 0.0) 30 31print("%.0f" % (1.750000 % 0.08333333333)) 32# Below isn't compatible with single-precision float 33# print("%.1f" % (1.750000 % 0.08333333333)) 34# print("%.2f" % (1.750000 % 0.08333333333)) 35# print("%.12f" % (1.750000 % 0.08333333333)) 36 37# tests for errors in format string 38 39try: 40 "{:10.1b}".format(0.0) 41except ValueError: 42 print("ValueError") 43