- % (modulo)
### % (modulo)

# % (modulo)

The % modulo is a binary operator that returns the integer remainder of dividing two operands. If the operands are real, they are truncated to integers beforehand.

If both

*x*and*y*are positive integers, we have:*x*%*y*If

*x*and*y*are positive real numbers, their floor values and are substituted in the above equation, i.e.:*x*%*y*With the notation that represents the value of

*x*truncated to the nearest integer towards zero, for example and , we have for the general case of real positive or negative operands:*x*%*y*In JavaScript, the expression above would be written:

- Math.trunc(
*x*) - Math.trunc(*y*)*Math.trunc(Math.trunc(*x*)/Math.trunc(*y*)) ## Syntax

*x*%*y*## Examples

**Operator****Returns****Explanation**35 % 20 15 -35 % 20 -15 35 % -20 15 -35 % -20 -15 12 % 3 0 5 % 8 5 15.7 % 4.3 3 -15.7 % 4.3 -3 15.7 % -4.3 3 -15.7 % -4.3 -3 15.5 % 3.9 0 0 % 7.9 0 7 % 0 Error 2 % 0.4 Error ## Note

In order to avoid having an error when abs(

*y*) floors to zero, it may be convenient to handle this case with the following code:moduloCatch=(abs(y)<1)?x:x % y;An arbitrary value of

*x*can be assigned to*x*%*y*and a warning message can be displayed.The Formulas question should look like this:

## References

## See also

The numerical function fmod().