/Doc/library/fpformat.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 61 lines · 36 code · 25 blank · 0 comment · 0 complexity · d9f43064e55b7fa969dad8b0720f601b MD5 · raw file

  1. :mod:`fpformat` --- Floating point conversions
  2. ==============================================
  3. .. module:: fpformat
  4. :synopsis: General floating point formatting functions.
  5. :deprecated:
  6. .. deprecated:: 2.6
  7. The :mod:`fpformat` module has been removed in Python 3.0.
  8. .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
  9. The :mod:`fpformat` module defines functions for dealing with floating point
  10. numbers representations in 100% pure Python.
  11. .. note::
  12. This module is unnecessary: everything here can be done using the ``%`` string
  13. interpolation operator described in the :ref:`string-formatting` section.
  14. The :mod:`fpformat` module defines the following functions and an exception:
  15. .. function:: fix(x, digs)
  16. Format *x* as ``[-]ddd.ddd`` with *digs* digits after the point and at least one
  17. digit before. If ``digs <= 0``, the decimal point is suppressed.
  18. *x* can be either a number or a string that looks like one. *digs* is an
  19. integer.
  20. Return value is a string.
  21. .. function:: sci(x, digs)
  22. Format *x* as ``[-]d.dddE[+-]ddd`` with *digs* digits after the point and
  23. exactly one digit before. If ``digs <= 0``, one digit is kept and the point is
  24. suppressed.
  25. *x* can be either a real number, or a string that looks like one. *digs* is an
  26. integer.
  27. Return value is a string.
  28. .. exception:: NotANumber
  29. Exception raised when a string passed to :func:`fix` or :func:`sci` as the *x*
  30. parameter does not look like a number. This is a subclass of :exc:`ValueError`
  31. when the standard exceptions are strings. The exception value is the improperly
  32. formatted string that caused the exception to be raised.
  33. Example::
  34. >>> import fpformat
  35. >>> fpformat.fix(1.23, 1)
  36. '1.2'