freeCodeCamp/guide/chinese/javascript/tutorials/finding-a-remainder-in-java.../index.md

494 B
Raw Blame History

title localeTitle
Finding a Remainder in JavaScript 在JavaScript中查找剩余内容

余数运算符 %给出了两个数的除法的余数。

5 % 2 = 1 because 
 Math.floor(5 / 2) = 2 (Quotient) 
 2 * 2 = 4 
 5 - 4 = 1 (Remainder) 

用法

在数学中通过检查数字除法的余数为2可以检查偶数或奇数。

17 % 2 = 1 (17 is Odd) 
 48 % 2 = 0 (48 is Even) 

注意不要将它与_模数_ %混淆,否则与负数不兼容。