Modulus Operator (JavaScript)

Divides the value of one expression by the value of another, and returns the remainder.

Syntax


result = number1 % number2  

Arguments

result
Any variable.

number1
Any numeric expression.

number2
Any numeric expression.

Remarks

The modulus, or remainder, operator divides number1 by number2and returns only the remainder as result. The sign of result is the same as the sign of number1. The value of result is between 0 and the absolute value of number2.

The following code shows how to use the modulus operator.

var modResult = 19 % 6.7;  
document.write(modResult);  

// Output: 5.6  

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

See Also

Operator Precedence
Operator Summary (JavaScript)