Scientific Notation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dustan

    Scientific Notation

    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

    #2
    Re: Scientific Notation

    Dustan <DustanGroups@g mail.com> wrote:
    [color=blue]
    > 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.[/color]

    You mean something like:
    [color=blue][color=green][color=darkred]
    >>> print '%e' % (1e50)[/color][/color][/color]
    1.000000e+50

    ....?


    Alex

    Comment

    • Dustan

      #3
      Re: Scientific Notation

      No, I mean given a big number, such as
      100000000000000 000000000000000 000000000000000 0000000, convert it into
      scientific notation.

      Comment

      • Roy Smith

        #4
        Re: Scientific Notation

        In article <1133664042.615 633.45570@g14g2 000cwa.googlegr oups.com>,
        "Dustan" <DustanGroups@g mail.com> wrote:
        [color=blue]
        > 100000000000000 000000000000000 000000000000000 0000000[/color]
        [color=blue][color=green][color=darkred]
        >>> print "%e" % 100000000000000 000000000000000 000000000000000 0000000[/color][/color][/color]
        1.000000e+51

        Comment

        • Alex Martelli

          #5
          Re: Scientific Notation

          Roy Smith <roy@panix.co m> wrote:
          [color=blue]
          > In article <1133664042.615 633.45570@g14g2 000cwa.googlegr oups.com>,
          > "Dustan" <DustanGroups@g mail.com> wrote:
          >[color=green]
          > > 100000000000000 000000000000000 000000000000000 0000000[/color]
          >[color=green][color=darkred]
          > >>> print "%e" % 100000000000000 000000000000000 000000000000000 0000000[/color][/color]
          > 1.000000e+51[/color]

          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:
          [color=blue][color=green][color=darkred]
          >>> print '%g' % 10**5[/color][/color][/color]
          100000[color=blue][color=green][color=darkred]
          >>> print '%g' % 10**50[/color][/color][/color]
          1e+50


          Alex

          Comment

          • Jorge Godoy

            #6
            Re: Scientific Notation

            "Dustan" <DustanGroups@g mail.com> writes:
            [color=blue]
            > No, I mean given a big number, such as
            > 100000000000000 000000000000000 000000000000000 0000000, convert it into
            > scientific notation.[/color]

            It's the same.
            [color=blue][color=green][color=darkred]
            >>> print "%e" % 100000000000000 000000000000000 000000000000000 0000000[/color][/color][/color]
            1.000000e+51


            --
            Jorge Godoy <godoy@ieee.org >

            Comment

            • Fredrik Lundh

              #7
              Re: Scientific Notation

              > > > You mean something like:[color=blue][color=green][color=darkred]
              > > >
              > > > >>> print '%e' % (1e50)
              > > > 1.000000e+50
              > > >
              > > > ...?[/color][/color]
              >[color=green]
              > > No, I mean given a big number, such as
              > > 100000000000000 000000000000000 000000000000000 0000000, convert it into
              > > scientific notation.[/color]
              >
              > It's the same.
              >[color=green][color=darkred]
              > >>> print "%e" % 100000000000000 000000000000000 000000000000000 0000000[/color][/color]
              > 1.000000e+51[/color]

              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>



              Comment

              • Dustan

                #8
                Re: Scientific Notation

                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.

                Comment

                Working...