Modulo Calculator

The remainder of a division. Shows both the maths answer and what a computer % gives for negatives.

How it works

The modulo operation gives the remainder after dividing a by n. For positive numbers it is simple: 17 mod 5 = 2. For negatives, mathematics and programming languages disagree, so the tool shows both: the maths answer (always 0 or positive for a positive n) and the result of % in C, Java and JavaScript (which keeps the sign of the dividend).

Worked example

-7 mod 3 is 2 in maths (because -7 = 3 x -3 + 2) but -7 % 3 is -1 in JavaScript. Python gives 2.

Good to know

Common questions

Why is -7 % 3 negative in JavaScript?
JavaScript truncates the quotient toward zero, so the remainder takes the sign of the dividend.
What is the result of a mod 1?
Always 0 for whole numbers.
Can the divisor be negative?
Yes. The tool shows the floor based result.

More in Utilities.