2 :mod:`fpformat` --- Floating point conversions
3 ==============================================
6 :synopsis: General floating point formatting functions.
10 The :mod:`fpformat` module has been removed in Python 3.0.
12 .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
15 The :mod:`fpformat` module defines functions for dealing with floating point
16 numbers representations in 100% pure Python.
20 This module is unnecessary: everything here can be done using the ``%`` string
21 interpolation operator described in the :ref:`string-formatting` section.
23 The :mod:`fpformat` module defines the following functions and an exception:
26 .. function:: fix(x, digs)
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.
31 *x* can be either a number or a string that looks like one. *digs* is an
34 Return value is a string.
37 .. function:: sci(x, digs)
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
43 *x* can be either a real number, or a string that looks like one. *digs* is an
46 Return value is a string.
49 .. exception:: NotANumber
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.
59 >>> fpformat.fix(1.23, 1)