Scientific Notation

Alex Martelli aleax at mail.comcast.net
Sat Dec 3 21:46:47 EST 2005


Roy Smith <roy at panix.com> wrote:

> In article <1133664042.615633.45570 at g14g2000cwa.googlegroups.com>,
>  "Dustan" <DustanGroups at gmail.com> wrote:
> 
> > 1000000000000000000000000000000000000000000000000000
> 
> >>> print "%e" % 1000000000000000000000000000000000000000000000000000
> 1.000000e+51

Exactly: the "%e" builds a ``scientific-notation" string from whatever
number you're formatting that way (big or small).  You can also use %g
if what you want is fixed-point notation within a certain range and
scientific notations only for numbers OUTSIDE that range, as in:

>>> print '%g' % 10**5
100000
>>> print '%g' % 10**50
1e+50


Alex



More information about the Python-list mailing list