How convert string '1e7' to an integer?

Benjamin Kaplan benjamin.kaplan at
Sun Nov 8 02:52:37 CET 2009

On Sat, Nov 7, 2009 at 8:17 PM, Peng Yu <pengyu.ut at> 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

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

> --

More information about the Python-list mailing list