Java: why 7 / -3 -2?

Why is java 7 / -3 not -3? This is -2. I thought the division result is rounded. In python 2 it is -3. Is there any other rule for division in java?

+4
source share
1 answer

Is there any other rule for division in java?

As always, for such questions you should go to the Java Language Specification . In this case, the relevant section 15.17.2 :

. , n d, (§5.6.2), q, |d ⋅ q| ≤ |n|. , q , |n| ≥ |d| n d , q , |n| ≥ |d| n d .

, "" " ", : -99/50 -1. 0.

, Java , Python , , , , . . , - Python - , ( 15.17.3):

, (§5.6.2), , , (a/b)*b+(a%b) a.

+14

All Articles