GNU Info

Info Node: (python2.1-lib.info)fpformat

(python2.1-lib.info)fpformat


Next: StringIO Prev: difflib Up: String Services
Enter node , (file) or (file)node

Floating point conversions
==========================

This manual section was written by Moshe Zadka
<moshez@zadka.site.co.il>.
General floating point formatting functions.

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

The `fpformat' module defines the following functions and an exception:

`fix(x, digs)'
     Format X as `[-]ddd.ddd' with DIGS digits after the point and at
     least one digit before.  If `DIGS <= 0', the decimal point is
     suppressed.

     X can be either a number or a string that looks like one. DIGS is
     an integer.

     Return value is a string.

`sci(x, digs)'
     Format X as `[-]d.dddE[+-]ddd' with DIGS digits after the point
     and exactly one digit before.  If `DIGS <= 0', one digit is kept
     and the point is suppressed.

     X can be either a real number, or a string that looks like one.
     DIGS is an integer.

     Return value is a string.

`NotANumber'
     Exception raised when a string passed to `fix()' or `sci()' as the
     X parameter does not look like a number.  This is a subclass of
     `ValueError' when the standard exceptions are strings.  The
     exception value is the improperly formatted string that caused the
     exception to be raised.

Example:

     >>> import fpformat
     >>> fpformat.fix(1.23, 1)
     '1.2'


automatically generated by info2www version 1.2.2.9