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

Discussion in 'Python' started by MRAB, Nov 8, 2009.

  1. MRAB

    MRAB Guest

    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'


    In Python the e-form indicates a float, as does the presence of a
    decimal point, but you can convert to float and then to int:

    >>> int(float('1e7'))

    10000000
     
    MRAB, 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,954
    Mick Krippendorf
    Nov 8, 2009
  3. Benjamin Kaplan

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

    Benjamin Kaplan, Nov 8, 2009, in forum: Python
    Replies:
    0
    Views:
    912
    Benjamin Kaplan
    Nov 8, 2009
  4. news
    Replies:
    2
    Views:
    1,134
  5. Randy Kramer
    Replies:
    12
    Views:
    403
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page