int('2.1') does not work while int(float('2.1')) does

Vineet Jain vineet at eswap.com
Tue Apr 6 00:43:47 EDT 2004


Just an interesting thing to note:

>>> a = int(float(0.99999999999999999))
>>> a
1
>>> a = int(float(0.9999999999999999))
>>> a
0

I'm still not sure i follow why "int(aString) means make an int out of this
string" cannot use the same rules and behave in the same way as it encouters
a float when it encouters a float string.

VJ

-----Original Message-----
From: python-list-bounces+vineet=eswap.com at python.org
[mailto:python-list-bounces+vineet=eswap.com at python.org]On Behalf Of
Erik Max Francis
Sent: Monday, April 05, 2004 11:14 PM
To: python-list at python.org
Subject: Re: int('2.1') does not work while int(float('2.1')) does


Joe Mason wrote:

> Why can it make this guess for "int(2.1)", then?  It's got a rule for
> converting floats to ints - why not use it here?

Because int(aFloat) means round toward zero.  int(aString) means make an
int out of this string.

--
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Convictions are more dangerous enemies of truth than lies.
    -- Friedrich Nietzsche
--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list