JavaScript 中 10/5 和 10%5 有什么区别?
JavaScript 中 10/5 和 10%5 有什么区别?两者都一样吗?
What is difference between 10/5 and 10%5 in JavaScript? Are both same ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
%
是模数%
is modulo一个是基本除法运算:
另一个是模运算符,它将给出除法运算的整数余数。
One is your basic division operation:
The other is the modulo operator, which will give you the integer remainder of the division operation.
10/5 是除法运算,根据存储结果的数据类型,可能不会给出预期的结果。如果存储在 int 中,您将丢失其余部分。
10%2 是模运算。它将返回除法的余数,通常用于确定数字是奇数还是偶数。取任何给定的数字 mod 2 (N%2),如果结果是 0,那么您就知道该数字是偶数。
10/5 is division operation and depending on the data type storing the result in might not give you the result expected. if storing in a int you will loose the remainder.
10%2 is a modulus operation. it will return the remainder from the division and is commonly used to determine if a number is odd or even. take any given number mod 2 (N%2) and if the result is is 0 then you know the number is even.
10/5 除 10/5 = 2
10%5 除 5 并返回余数 0,因此
10%5 = 0
10/5 divides 10/5 = 2
10%5 divides 5 and returns the remainder, 0, so
10%5 = 0
http://www.w3schools.com/js/js_operators.asp
10 / 5 是2.
10%5就是0。
http://www.w3schools.com/js/js_operators.asp
10 / 5 is 2.
10 % 5 is 0.
在几乎每种语言中 % 都是模数而不是除号。它确实除法,但它只给出余数而不是除后的数字。
In pretty much every language % is a modulus not a divide symbol. It does divide but it gives you just the remainder rather than the divided number.
% 是模运算符:它给出除法的余数。
% is the modulus operator: it gives you the remainder of the division.
10 / 5 是 10 除以 5,或基本除法。
10 % 5 是 10 模 5,或除法运算的余数。
10 / 5 is 10 divided by 5, or basic division.
10 % 5 is 10 modulo 5, or the remainder of a division operation.