blob: 3448585609920d44f9c5d49f187155b824f6df78 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`fpformat` --- Floating point conversions
3==============================================
4
5.. module:: fpformat
6 :synopsis: General floating point formatting functions.
Brett Cannonfe598512008-05-10 22:11:45 +00007 :deprecated:
Georg Brandlc62ef8b2009-01-03 20:55:06 +00008
Brett Cannonfe598512008-05-10 22:11:45 +00009.. deprecated:: 2.6
Brett Cannona975cd42008-05-11 01:06:54 +000010 The :mod:`fpformat` module has been removed in Python 3.0.
Georg Brandlc62ef8b2009-01-03 20:55:06 +000011
Georg Brandl8ec7f652007-08-15 14:28:01 +000012.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
13
14
15The :mod:`fpformat` module defines functions for dealing with floating point
16numbers representations in 100% pure Python.
17
18.. note::
19
Mark Summerfield7f626f42007-08-30 15:03:03 +000020 This module is unnecessary: everything here can be done using the ``%`` string
21 interpolation operator described in the :ref:`string-formatting` section.
Georg Brandl8ec7f652007-08-15 14:28:01 +000022
23The :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
56Example::
57
58 >>> import fpformat
59 >>> fpformat.fix(1.23, 1)
60 '1.2'
61