ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: How convert string '1e7' to an integer?
by Roel Schroeven other posts by this author
Nov 8 2009 1:41AM messages near this date
Re: How convert string '1e7' to an integer? | Re: How convert string '1e7' to an integer?
Gary Herron schreef:
>  Mensanator wrote:
> > On Nov 7, 7:17 pm, Peng Yu <pengyu...@[...].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'))
>  10000000
>  
>  That has a problem though, if you surpass the ability of a float:
>  
>   >>> int(float('1e20'))
>  100000000000000000000L
>   >>> int(float('1e30'))
>  1000000000000000019884624838656L

If that is a concern, decimal can help:

> >> import decimal
> >> int(decimal.Decimal('1e30'))
1000000000000000000000000000000L

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Peng Yu
Christian Heimes
Thomas
Mick Krippendorf
Roel Schroeven
Benjamin Kaplan
Mrab
Ben Finney
Mensanator
Gary Herron
Mick Krippendorf
Tim Chase

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved