# Scientific Notation

Discussion in 'Python' started by Dustan, Dec 4, 2005.

1. ### DustanGuest

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.
Dustan, Dec 4, 2005

2. ### Alex MartelliGuest

Dustan <> 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
Alex Martelli, Dec 4, 2005

3. ### DustanGuest

No, I mean given a big number, such as
1000000000000000000000000000000000000000000000000000, convert it into
scientific notation.
Dustan, Dec 4, 2005
4. ### Roy SmithGuest

In article <>,
"Dustan" <> wrote:

> 1000000000000000000000000000000000000000000000000000

>>> print "%e" % 1000000000000000000000000000000000000000000000000000

1.000000e+51
Roy Smith, Dec 4, 2005
5. ### Jorge GodoyGuest

"Dustan" <> writes:

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

It's the same.

>>> print "%e" % 1000000000000000000000000000000000000000000000000000

1.000000e+51

--
Jorge Godoy <>
Jorge Godoy, Dec 4, 2005
6. ### Alex MartelliGuest

Roy Smith <> wrote:

> In article <>,
> "Dustan" <> 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
Alex Martelli, Dec 4, 2005
7. ### Fredrik LundhGuest

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

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

>
> It's the same.
>
> >>> print "%e" % 1000000000000000000000000000000000000000000000000000

> 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>
Fredrik Lundh, Dec 4, 2005
8. ### DustanGuest

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.
Dustan, Dec 4, 2005

### Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.