Integer Division

Piet van Oostrum piet at cs.uu.nl
Fri Jun 19 13:29:21 CEST 2009


>>>>> Anjanesh Lekshminarayanan <mail at anjanesh.net> (AL) escribió:

>>>>> a = 1
>>>>> b = 25
>>>>> a / b
>AL> 0
>>>>> float(a) / b
>AL> 0.040000000000000001
>>>>> 

>>>>> from __future__ import division
>>>>> a = 1
>>>>> b = 25
>>>>> a / b
>AL> 0.040000000000000001
>>>>> 

>AL> In what simple way can I get just 0.04 ?

In addition to the answers others have given:

>>> 0.04
0.040000000000000001
>>> 

IIRC, Python 3.1 will give 0.04. But this doesn't mean the answer will
be mathematically equal to 0.04, just that it tries to make it less
painful. 
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list