Integer and float division [was Re: Why Python 3?]

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Apr 20 11:09:36 EDT 2014


On Sun, 20 Apr 2014 15:38:03 +0300, Jussi Piitulainen wrote:

> Steven D'Aprano writes:
> 
>> It doesn't round, it truncates.
>> 
>> [steve at ando ~]$ python2.7 -c "print round(799.0/100)" 8.0
>> [steve at ando ~]$ python2.7 -c "print 799/100" 7
> 
> Seems it floors rather than truncates:
> 
> $ python2.7 -c "from math import trunc;print trunc(799./-100)" -7
> $ python2.7 -c "from math import floor;print floor(799./-100)" -8.0
> $ python2.7 -c "print 799/-100"
> -8
> 
> $ python3.2 -c "print(799//-100)"
> -8


Ah yes, so it does. Sorry for the confusion. This has been reported as a 
bug at least twice, but it is actually working as intended. // floors, 
not truncates towards zero.

http://bugs.python.org/issue19446
http://bugs.python.org/issue19574



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list