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