Home  >  Article  >  Web Front-end  >  Does javascript have a remainder function?

Does javascript have a remainder function?

青灯夜游
青灯夜游Original
2022-03-28 19:33:411796browse

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".

Does javascript have a remainder function?

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

Does javascript have a remainder function?

## Modulo arithmetic mainly operates on integers, but also applies to floating point numbers. For example:

console.log(3.1 % 2.3);  //返回余数0.8000000000000003

Does javascript have a remainder function?

The 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

Does javascript have a remainder function?

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn