blob: a3a62822308a277bab4815bc90ac6729824e3d35 [file] [log] [blame]
Fred Drake1739d2f1999-06-11 18:31:00 +00001\section{\module{fpformat} ---
2 Floating point conversions}
3
4\declaremodule{standard}{fpformat}
Fred Drake57657bc2000-12-01 15:25:23 +00005\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Fred Drake1739d2f1999-06-11 18:31:00 +00006\modulesynopsis{General floating point formatting functions.}
7
8
9The \module{fpformat} module defines functions for dealing with
10floating point numbers representations in 100\% pure
Fred Drake0aa811c2001-10-20 04:24:09 +000011Python. \note{This module is unneeded: everything here could
12be done via the \code{\%} string interpolation operator.}
Fred Drake1739d2f1999-06-11 18:31:00 +000013
14The \module{fpformat} module defines the following functions and an
15exception:
16
17
18\begin{funcdesc}{fix}{x, digs}
19Format \var{x} as \code{[-]ddd.ddd} with \var{digs} digits after the
20point and at least one digit before.
21If \code{\var{digs} <= 0}, the decimal point is suppressed.
22
23\var{x} can be either a number or a string that looks like
24one. \var{digs} is an integer.
25
26Return value is a string.
27\end{funcdesc}
28
29\begin{funcdesc}{sci}{x, digs}
30Format \var{x} as \code{[-]d.dddE[+-]ddd} with \var{digs} digits after the
31point and exactly one digit before.
32If \code{\var{digs} <= 0}, one digit is kept and the point is suppressed.
33
34\var{x} can be either a real number, or a string that looks like
35one. \var{digs} is an integer.
36
37Return value is a string.
38\end{funcdesc}
39
40\begin{excdesc}{NotANumber}
Fred Drakeb9bdfc61999-12-21 18:45:16 +000041Exception raised when a string passed to \function{fix()} or
42\function{sci()} as the \var{x} parameter does not look like a number.
43This is a subclass of \exception{ValueError} when the standard
44exceptions are strings. The exception value is the improperly
45formatted string that caused the exception to be raised.
Fred Drake1739d2f1999-06-11 18:31:00 +000046\end{excdesc}
47
48Example:
49
50\begin{verbatim}
51>>> import fpformat
52>>> fpformat.fix(1.23, 1)
53'1.2'
54\end{verbatim}