Home > Article > Backend Development > Why do the positive and negative values of php modulo operation depend on the dividend?
Just like the title. I only found that it is because it tends to zero, just like C and Java. I don’t quite understand why.
Just like the title. I only found that it is because it tends to zero, just like C and Java. I don’t quite understand why.
I just thought about it and found it easier to understand in reverse.
-20%3 = -2.
-20/3 = -6. 3*-6 +(-2) = -20
20%-3 = 2
20/-3 = -6 (-3)*(-6) = 18 + 2 = 20