How convert string '1e7' to an integer?
rschroev_nospam_ml at fastmail.fm
Sun Nov 8 10:37:34 CET 2009
Gary Herron schreef:
> Mensanator wrote:
>> On Nov 7, 7:17 pm, Peng Yu <pengyu... at gmail.com> wrote:
>>> It seems that int() does not convert '1e7'.
>> Because 'e' isn't a valid character in base 10.
> But 1e7 is a valid float, so this works:
> >>> int(float('1e7'))
> That has a problem though, if you surpass the ability of a float:
> >>> int(float('1e20'))
> >>> int(float('1e30'))
If that is a concern, decimal can help:
>>> import decimal
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
-- Isaac Asimov
More information about the Python-list