Re: How convert string '1e7' to an integer?

Discussion in 'Python' started by Benjamin Kaplan, Nov 8, 2009.

  1. On Sat, Nov 7, 2009 at 8:17 PM, Peng Yu <> wrote:
    > It seems that int() does not convert '1e7'. I'm wondering what
    > function to use to convert '1e7' to an integer?
    >
    >>>> int('1e7')

    > Traceback (most recent call last):
    >  File "<stdin>", line 1, in <module>
    > ValueError: invalid literal for int() with base 10: '1e7'


    Whenever you use that notation, you always get a float

    >>> 1e7

    10000000.0

    So to convert '1e7' to a number, you need to use float('1e7') which
    you can then convert to an int
    >>> int(float('1e7'))

    10000000



    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    Benjamin Kaplan, Nov 8, 2009
    #1
    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. les ander
    Replies:
    4
    Views:
    921
    wes weston
    Oct 5, 2004
  2. Peng Yu
    Replies:
    7
    Views:
    8,967
    Mick Krippendorf
    Nov 8, 2009
  3. MRAB
    Replies:
    0
    Views:
    449
  4. news
    Replies:
    2
    Views:
    1,134
  5. Randy Kramer
    Replies:
    12
    Views:
    403
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page