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