模数有什么作用?

What does the modulus do?

我从来没有真正理解它,但是模数运算符 (%) 是做什么的。

你什么时候想在数学环境中使用它?顺便说一下,我

只想知道它的作用,而不是它是如何工作的。

计算除法运算的remainder

5 / 2 == 2   // whole part of the division
5 % 2 == 1   // remainder

换句话说,您可以通过

重建原始数字
2 * 2 + 1 == 5
|   |   ^ remainder
|   ^ whole part
^ divisor