About Modulo Calculator
Enter a dividend and a divisor to get the remainder and the whole-number quotient. For positive numbers every convention agrees, but with negatives they split: −17 % 5 is −2 in JavaScript and C, yet −17 mod 5 is 3 in Python and in mathematics.
This tool shows all three conventions side by side, with the languages and spreadsheets that use each, and checks every answer against a = q × n + r. Whole numbers of up to 1,000 digits are handled exactly.
How it works
- Every convention satisfies a = q × n + r. They differ only in how the quotient q is rounded, and the remainder r follows from it.
- Truncated division rounds q toward zero, so r has the sign of a. Floored division rounds q down, so r has the sign of n. Euclidean division chooses q so that r is never negative.
- The headline modulo is the Euclidean one, the usual meaning in mathematics. For a positive divisor it matches Python and spreadsheet MOD.
- Arithmetic uses exact whole numbers in your browser; nothing is rounded and nothing is sent anywhere.
Questions
Why does JavaScript give −2 for −17 % 5 when Python gives 3?
JavaScript’s % operator is a truncated remainder: it rounds the quotient −3.4 toward zero to −3, leaving −17 − (−15) = −2. Python’s % rounds the quotient down to −4, leaving −17 − (−20) = 3.
How do I get a non-negative result in JavaScript?
Use ((a % n) + n) % n for a positive n. It gives the same answer as the Euclidean column here.
Can I use decimals?
No. This tool works with whole numbers, which is where the conventions matter and where exact answers are possible. Decimal inputs are refused with a message.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.