如何在 JavaScript 中使用模运算符 (%)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16505559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:56:48  来源:igfitidea点击:

How can I use modulo operator (%) in JavaScript?

javascriptcharcharacter

提问by Ziyaddin Sadigov

How can I use modulo operator (%) in calculation of numbers for JavaScript projects?

如何在 JavaScript 项目的数字计算中使用模运算符 (%)?

回答by MarioDS

It's the remainder operatorand is used to get the remainder after integer division. Lots of languages have it. For example:

它是余数运算符,用于获取整数除法后的余数。很多语言都有。例如:

10 % 3 // = 1 ; because 3 * 3 gets you 9, and 10 - 9 is 1.

Apparently it is not the same as the modulo operatorentirely.

显然它与模运算符完全不同。

回答by Joseph

That would be the modulo operator, which produces the remainder of the division of two numbers.

那将是模运算符,它产生两个数字相除的余数。