Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How convert string '1e7' to an integer?

Reply
Thread Tools

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

 
 
Benjamin Kaplan
Guest
Posts: n/a
 
      11-08-2009
On Sat, Nov 7, 2009 at 8:17 PM, Peng Yu <(E-Mail Removed)> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Convert formatted string to string? rockdale ASP .Net 3 04-12-2006 03:01 PM
convert string to raw string? Phd Python 3 12-06-2004 04:36 PM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= ASP .Net 2 10-26-2004 02:43 PM
Convert string to a string array Andrew Banks ASP .Net 2 04-19-2004 04:45 PM



Advertisments