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

23 lines
494 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Finding a Remainder in JavaScript
localeTitle: 在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)
```
**注意**不要将它与_模数_ `%`混淆,否则与负数不兼容。