Expand Minimize
3 out of 4 rated this helpful - Rate this topic

Modulus Operator (JavaScript)

JavaScript - Internet Explorer 10

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

result = number1 % number2
result

Any variable.

number1

Any numeric expression.

number2

Any numeric expression.

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

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. Also supported in Windows Store apps. See Version Information.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.