summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libfpformat.tex
blob: 94e434c2b99a2ed0998647e545cbd5cee544c8a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
\section{\module{fpformat} ---
         Floating point conversions}

\declaremodule{standard}{fpformat}
\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
\modulesynopsis{General floating point formatting functions.}


The \module{fpformat} module defines functions for dealing with
floating point numbers representations in 100\% pure
Python. \strong{Note:}  This module is unneeded: everything here could
be done via the \code{\%} string interpolation operator.

The \module{fpformat} module defines the following functions and an
exception:


\begin{funcdesc}{fix}{x, digs}
Format \var{x} as \code{[-]ddd.ddd} with \var{digs} digits after the
point and at least one digit before.
If \code{\var{digs} <= 0}, the decimal point is suppressed.

\var{x} can be either a number or a string that looks like
one. \var{digs} is an integer.

Return value is a string.
\end{funcdesc}

\begin{funcdesc}{sci}{x, digs}
Format \var{x} as \code{[-]d.dddE[+-]ddd} with \var{digs} digits after the 
point and exactly one digit before.
If \code{\var{digs} <= 0}, one digit is kept and the point is suppressed.

\var{x} can be either a real number, or a string that looks like
one. \var{digs} is an integer.

Return value is a string.
\end{funcdesc}

\begin{excdesc}{NotANumber}
Exception raised when a string does not look like a number when the 
documentation says it should.
\end{excdesc}

Example:

\begin{verbatim}
>>> import fpformat
>>> fpformat.fix(1.23, 1)
'1.2'
\end{verbatim}