float_format.py 607 B

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