How convert string '1e7' to an integer?
Benjamin Kaplan
benjamin.kaplan at case.edu
Sat Nov 7 20:52:37 EST 2009
On Sat, Nov 7, 2009 at 8:17 PM, Peng Yu <pengyu.ut at gmail.com> 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
>
More information about the Python-list
mailing list