korsygfhrtzangaiide
Elepffwdsff
/
usr
/
share
/
doc
/
python-docs-2.7.5
/
html
/
library
/
Upload FileeE
HOME
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>7.11. fpformat — Floating point conversions — Python 2.7.5 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.7.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.5 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="top" title="Python 2.7.5 documentation" href="../index.html" /> <link rel="up" title="7. String Services" href="strings.html" /> <link rel="next" title="8. Data Types" href="datatypes.html" /> <link rel="prev" title="7.10. stringprep — Internet String Preparation" href="stringprep.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="datatypes.html" title="8. Data Types" accesskey="N">next</a> |</li> <li class="right" > <a href="stringprep.html" title="7.10. stringprep — Internet String Preparation" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="strings.html" accesskey="U">7. String Services</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-fpformat"> <span id="fpformat-floating-point-conversions"></span><h1>7.11. <a class="reference internal" href="#module-fpformat" title="fpformat: General floating point formatting functions. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">fpformat</span></tt></a> — Floating point conversions<a class="headerlink" href="#module-fpformat" title="Permalink to this headline">¶</a></h1> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.6: </span>The <a class="reference internal" href="#module-fpformat" title="fpformat: General floating point formatting functions. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">fpformat</span></tt></a> module has been removed in Python 3.</p> <p>The <a class="reference internal" href="#module-fpformat" title="fpformat: General floating point formatting functions. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">fpformat</span></tt></a> module defines functions for dealing with floating point numbers representations in 100% pure Python.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This module is unnecessary: everything here can be done using the <tt class="docutils literal"><span class="pre">%</span></tt> string interpolation operator described in the <a class="reference internal" href="stdtypes.html#string-formatting"><em>String Formatting Operations</em></a> section.</p> </div> <p>The <a class="reference internal" href="#module-fpformat" title="fpformat: General floating point formatting functions. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">fpformat</span></tt></a> module defines the following functions and an exception:</p> <dl class="function"> <dt id="fpformat.fix"> <tt class="descclassname">fpformat.</tt><tt class="descname">fix</tt><big>(</big><em>x</em>, <em>digs</em><big>)</big><a class="headerlink" href="#fpformat.fix" title="Permalink to this definition">¶</a></dt> <dd><p>Format <em>x</em> as <tt class="docutils literal"><span class="pre">[-]ddd.ddd</span></tt> with <em>digs</em> digits after the point and at least one digit before. If <tt class="docutils literal"><span class="pre">digs</span> <span class="pre"><=</span> <span class="pre">0</span></tt>, the decimal point is suppressed.</p> <p><em>x</em> can be either a number or a string that looks like one. <em>digs</em> is an integer.</p> <p>Return value is a string.</p> </dd></dl> <dl class="function"> <dt id="fpformat.sci"> <tt class="descclassname">fpformat.</tt><tt class="descname">sci</tt><big>(</big><em>x</em>, <em>digs</em><big>)</big><a class="headerlink" href="#fpformat.sci" title="Permalink to this definition">¶</a></dt> <dd><p>Format <em>x</em> as <tt class="docutils literal"><span class="pre">[-]d.dddE[+-]ddd</span></tt> with <em>digs</em> digits after the point and exactly one digit before. If <tt class="docutils literal"><span class="pre">digs</span> <span class="pre"><=</span> <span class="pre">0</span></tt>, one digit is kept and the point is suppressed.</p> <p><em>x</em> can be either a real number, or a string that looks like one. <em>digs</em> is an integer.</p> <p>Return value is a string.</p> </dd></dl> <dl class="exception"> <dt id="fpformat.NotANumber"> <em class="property">exception </em><tt class="descclassname">fpformat.</tt><tt class="descname">NotANumber</tt><a class="headerlink" href="#fpformat.NotANumber" title="Permalink to this definition">¶</a></dt> <dd><p>Exception raised when a string passed to <a class="reference internal" href="#fpformat.fix" title="fpformat.fix"><tt class="xref py py-func docutils literal"><span class="pre">fix()</span></tt></a> or <a class="reference internal" href="#fpformat.sci" title="fpformat.sci"><tt class="xref py py-func docutils literal"><span class="pre">sci()</span></tt></a> as the <em>x</em> parameter does not look like a number. This is a subclass of <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> when the standard exceptions are strings. The exception value is the improperly formatted string that caused the exception to be raised.</p> </dd></dl> <p>Example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">fpformat</span> <span class="gp">>>> </span><span class="n">fpformat</span><span class="o">.</span><span class="n">fix</span><span class="p">(</span><span class="mf">1.23</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="go">'1.2'</span> </pre></div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="stringprep.html" title="previous chapter">7.10. <tt class="docutils literal"><span class="pre">stringprep</span></tt> — Internet String Preparation</a></p> <h4>Next topic</h4> <p class="topless"><a href="datatypes.html" title="next chapter">8. Data Types</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li><a href="../_sources/library/fpformat.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="datatypes.html" title="8. Data Types" >next</a> |</li> <li class="right" > <a href="stringprep.html" title="7.10. stringprep — Internet String Preparation" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="strings.html" >7. String Services</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="http://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Jul 03, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>