Question about slight deviations when using integer division with large integers.
cseberino at gmail.com
Mon Dec 31 13:23:39 EST 2018
Thanks to all who helped. As was previously pointed out, many other languages
use truncation rather than rounding for // division.
Getting the behavior you want may be as easy as replacing // with the int()
>>> x = 9 ; y = 2
>>> x // y, -x // y, (-x) // y
(4, -5, -5)
>>> int(x / y), -int(x / y), int(-x / y)
(4, -4, -4)
Hope that helps.
More information about the Python-list