Scientific Notation

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

  1. Dustan

    Dustan Guest

    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
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

  3. Dustan

    Dustan Guest

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

    Roy Smith Guest

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

    > 1000000000000000000000000000000000000000000000000000


    >>> print "%e" % 1000000000000000000000000000000000000000000000000000

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

    Jorge Godoy Guest

    "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
    #5
  6. 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
    #6
  7. > > > 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
    #7
  8. Dustan

    Dustan Guest

    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
    #8
    1. Advertising

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.
Similar Threads
  1. Ville Ahonen

    No scientific notation?

    Ville Ahonen, Oct 19, 2004, in forum: C++
    Replies:
    2
    Views:
    439
    Mike Wahler
    Oct 19, 2004
  2. grinder

    reguarding scientific notation

    grinder, Aug 28, 2006, in forum: C Programming
    Replies:
    7
    Views:
    442
    Knemon
    Aug 29, 2006
  3. asdf
    Replies:
    2
    Views:
    531
    Rolf Magnus
    Oct 21, 2006
  4. N1GHTS

    Scientific Notation Conversion

    N1GHTS, Feb 20, 2008, in forum: C Programming
    Replies:
    1
    Views:
    561
    N1GHTS
    Feb 20, 2008
  5. Paul McNett

    Unexpected scientific notation

    Paul McNett, Jan 8, 2009, in forum: Python
    Replies:
    10
    Views:
    655
    Mark Dickinson
    Jan 9, 2009
Loading...

Share This Page