Home >Web Front-end >Front-end Q&A >Does javascript have a remainder function?
Javascript does not have a remainder function. In JavaScript, the remainder operation is implemented using the modulo operator "%". The syntax is "value 1% value 2", and the return value is the remainder sought; the "%" modulo operator mainly operates on integers, but Also applies to floating point numbers, such as "3.1 % 2.3".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
There is no remainder function in JavaScript, but the modulus operator "%" can be used to implement the remainder operation.
In JavaScript, the modulo operator "%", also known as the remainder operator, can perform division operations and obtain the remainder.
Syntax:
数值1 % 数值2
Example:
console.log(5 % 2); //返回余数1## Modulo arithmetic mainly operates on integers, but also applies to floating point numbers. For example:
console.log(3.1 % 2.3); //返回余数0.8000000000000003The value of the modular operation is consistent with the sign of the dividend.
console.log(-13 % 5); // 返回余数 -3 console.log(4 % -2); // 返回余数 0 console.log(-4 % 2); // 返回余数 -0[Related recommendations:
javascript video tutorial, web front-end】
The above is the detailed content of Does javascript have a remainder function?. For more information, please follow other related articles on the PHP Chinese website!