Integer division (again)

Hi all,

I realize that integer division has been discussed at length, but I haven’t been able to find a solution to my problem.
If I perform this most simple of commands in python:
print(int(3*42632001098429499/3))
I get
image
which I find extremely odd since 42632001098429499 is divisible by 3.
Anybody know how I can get a correct answer?
Thanks in advance!

This is performing floating point division when using / so you are limited by floating point precision. // would get you an integer value that matches what you expect.

2 Likes

I’m not even sure it is right to say // is integer division…but is floor division.

Since we know the value is exactly divisible by 3, it rounds to the nearest integer as expected.

1 Like

For more details, you can refer to:

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Thanks all for your quick responses. It worked a treat. Although I officially don’t need floor division in this case it works well.