I never really get it, but what does the modulus operator (%
) do.
And when would you want to use it in a mathematical context? By the way, I
just want to know what it does, not how it works.
I never really get it, but what does the modulus operator (%
) do.
And when would you want to use it in a mathematical context? By the way, I
just want to know what it does, not how it works.
It calculates the remainder of a division operation.
5 / 2 == 2 // whole part of the division
5 % 2 == 1 // remainder
In other words you could reconstruct the original number by
2 * 2 + 1 == 5
| | ^ remainder
| ^ whole part
^ divisor