Velocity Reviews > Scientific Notation

Scientific Notation

Dustan
Guest
Posts: n/a

 12-04-2005
How can I get a number into scientific notation? I have a preference
for the format '1 E 50' (as an example), but if it's well known, it
works.

Alex Martelli
Guest
Posts: n/a

 12-04-2005
Dustan <(E-Mail Removed)> wrote:

> How can I get a number into scientific notation? I have a preference
> for the format '1 E 50' (as an example), but if it's well known, it
> works.

You mean something like:

>>> print '%e' % (1e50)

1.000000e+50

....?

Alex

Dustan
Guest
Posts: n/a

 12-04-2005
No, I mean given a big number, such as
10000000000000000000000000000000000000000000000000 00, convert it into
scientific notation.

Roy Smith
Guest
Posts: n/a

 12-04-2005
In article <(E-Mail Removed). com>,
"Dustan" <(E-Mail Removed)> wrote:

> 10000000000000000000000000000000000000000000000000 00

>>> print "%e" % 10000000000000000000000000000000000000000000000000 00

1.000000e+51

Jorge Godoy
Guest
Posts: n/a

 12-04-2005
"Dustan" <(E-Mail Removed)> writes:

> No, I mean given a big number, such as
> 10000000000000000000000000000000000000000000000000 00, convert it into
> scientific notation.

It's the same.

>>> print "%e" % 10000000000000000000000000000000000000000000000000 00

1.000000e+51

--
Jorge Godoy <(E-Mail Removed)>

Alex Martelli
Guest
Posts: n/a

 12-04-2005
Roy Smith <(E-Mail Removed)> wrote:

> In article <(E-Mail Removed). com>,
> "Dustan" <(E-Mail Removed)> wrote:
>
> > 10000000000000000000000000000000000000000000000000 00

>
> >>> print "%e" % 10000000000000000000000000000000000000000000000000 00

> 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

Fredrik Lundh
Guest
Posts: n/a

 12-04-2005
> > > You mean something like:
> > >
> > > >>> print '%e' % (1e50)
> > > 1.000000e+50
> > >
> > > ...?

>
> > No, I mean given a big number, such as
> > 10000000000000000000000000000000000000000000000000 00, convert it into
> > scientific notation.

>
> It's the same.
>
> >>> print "%e" % 10000000000000000000000000000000000000000000000000 00

> 1.000000e+51

one would have assumed that someone who *prefers* to use scientific notation
for large numbers would in fact know that, but the usenet never ceases to sur-
prise me...

</F>

Dustan
Guest
Posts: n/a

 12-04-2005
Thanks for your help, Alex, Roy and Jorge. I'm new to Python, and
programming in general, which might explain my lack of knowledge,
Fredrick.