Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / module-fpformat.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="module-StringIO.html" />
13<link rel="prev" href="module-difflib.html" />
14<link rel="parent" href="strings.html" />
15<link rel="next" href="module-StringIO.html" />
16<meta name='aesop' content='information' />
17<title>4.5 fpformat -- Floating point conversions</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="4.4.4 Differ Example"
25 href="differ-examples.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="4. String Services"
28 href="strings.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="4.6 StringIO "
31 href="module-StringIO.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="differ-examples.html">4.4.4 Differ Example</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="strings.html">4. String Services</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="module-StringIO.html">4.6 StringIO </A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION006500000000000000000">
564.5 <tt class="module">fpformat</tt> --
57 Floating point conversions</A>
58</H1>
59
60<P>
61<A NAME="module-fpformat"></A>
62
63<P>
64The <tt class="module">fpformat</tt> module defines functions for dealing with
65floating point numbers representations in 100% pure
66Python. <span class="note"><b class="label">Note:</b>
67This module is unneeded: everything here could
68be done via the <code>%</code> string interpolation operator.</span>
69
70<P>
71The <tt class="module">fpformat</tt> module defines the following functions and an
72exception:
73
74<P>
75<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
76 <td><nobr><b><tt id='l2h-950' xml:id='l2h-950' class="function">fix</tt></b>(</nobr></td>
77 <td><var>x, digs</var>)</td></tr></table></dt>
78<dd>
79Format <var>x</var> as <code>[-]ddd.ddd</code> with <var>digs</var> digits after the
80point and at least one digit before.
81If <code><var>digs</var> &lt;= 0</code>, the decimal point is suppressed.
82
83<P>
84<var>x</var> can be either a number or a string that looks like
85one. <var>digs</var> is an integer.
86
87<P>
88Return value is a string.
89</dl>
90
91<P>
92<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
93 <td><nobr><b><tt id='l2h-951' xml:id='l2h-951' class="function">sci</tt></b>(</nobr></td>
94 <td><var>x, digs</var>)</td></tr></table></dt>
95<dd>
96Format <var>x</var> as <code>[-]d.dddE[+-]ddd</code> with <var>digs</var> digits after the
97point and exactly one digit before.
98If <code><var>digs</var> &lt;= 0</code>, one digit is kept and the point is suppressed.
99
100<P>
101<var>x</var> can be either a real number, or a string that looks like
102one. <var>digs</var> is an integer.
103
104<P>
105Return value is a string.
106</dl>
107
108<P>
109<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-952' xml:id='l2h-952' class="exception">NotANumber</tt></b></dt>
110<dd>
111Exception raised when a string passed to <tt class="function">fix()</tt> or
112<tt class="function">sci()</tt> as the <var>x</var> parameter does not look like a number.
113This is a subclass of <tt class="exception">ValueError</tt> when the standard
114exceptions are strings. The exception value is the improperly
115formatted string that caused the exception to be raised.
116</dd></dl>
117
118<P>
119Example:
120
121<P>
122<div class="verbatim"><pre>
123&gt;&gt;&gt; import fpformat
124&gt;&gt;&gt; fpformat.fix(1.23, 1)
125'1.2'
126</pre></div>
127
128<DIV CLASS="navigation">
129<div class='online-navigation'>
130<p></p><hr />
131<table align="center" width="100%" cellpadding="0" cellspacing="2">
132<tr>
133<td class='online-navigation'><a rel="prev" title="4.4.4 Differ Example"
134 href="differ-examples.html"><img src='../icons/previous.png'
135 border='0' height='32' alt='Previous Page' width='32' /></A></td>
136<td class='online-navigation'><a rel="parent" title="4. String Services"
137 href="strings.html"><img src='../icons/up.png'
138 border='0' height='32' alt='Up One Level' width='32' /></A></td>
139<td class='online-navigation'><a rel="next" title="4.6 StringIO "
140 href="module-StringIO.html"><img src='../icons/next.png'
141 border='0' height='32' alt='Next Page' width='32' /></A></td>
142<td align="center" width="100%">Python Library Reference</td>
143<td class='online-navigation'><a rel="contents" title="Table of Contents"
144 href="contents.html"><img src='../icons/contents.png'
145 border='0' height='32' alt='Contents' width='32' /></A></td>
146<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
147 border='0' height='32' alt='Module Index' width='32' /></a></td>
148<td class='online-navigation'><a rel="index" title="Index"
149 href="genindex.html"><img src='../icons/index.png'
150 border='0' height='32' alt='Index' width='32' /></A></td>
151</tr></table>
152<div class='online-navigation'>
153<b class="navlabel">Previous:</b>
154<a class="sectref" rel="prev" href="differ-examples.html">4.4.4 Differ Example</A>
155<b class="navlabel">Up:</b>
156<a class="sectref" rel="parent" href="strings.html">4. String Services</A>
157<b class="navlabel">Next:</b>
158<a class="sectref" rel="next" href="module-StringIO.html">4.6 StringIO </A>
159</div>
160</div>
161<hr />
162<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
163</DIV>
164<!--End of Navigation Panel-->
165<ADDRESS>
166See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
167</ADDRESS>
168</BODY>
169</HTML>