2 :mod:`fpformat` --- Floating point conversions
3 ==============================================
6 :synopsis: General floating point formatting functions.
7 .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
10 The :mod:`fpformat` module defines functions for dealing with floating point
11 numbers representations in 100% pure Python.
15 This module is unnecessary: everything here can be done using the ``%`` string
16 interpolation operator described in the :ref:`string-formatting` section.
18 The :mod:`fpformat` module defines the following functions and an exception:
21 .. function:: fix(x, digs)
23 Format *x* as ``[-]ddd.ddd`` with *digs* digits after the point and at least one
24 digit before. If ``digs <= 0``, the decimal point is suppressed.
26 *x* can be either a number or a string that looks like one. *digs* is an
29 Return value is a string.
32 .. function:: sci(x, digs)
34 Format *x* as ``[-]d.dddE[+-]ddd`` with *digs* digits after the point and
35 exactly one digit before. If ``digs <= 0``, one digit is kept and the point is
38 *x* can be either a real number, or a string that looks like one. *digs* is an
41 Return value is a string.
44 .. exception:: NotANumber
46 Exception raised when a string passed to :func:`fix` or :func:`sci` as the *x*
47 parameter does not look like a number. This is a subclass of :exc:`ValueError`
48 when the standard exceptions are strings. The exception value is the improperly
49 formatted string that caused the exception to be raised.
54 >>> fpformat.fix(1.23, 1)