string_format_fp30.py 1002 B

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