Modulo calculator

For negative numbers, math (and Python) give a remainder with the sign of the divisor; C, Java and JavaScript give it the sign of the dividend.

Your answer

a mod n (floored, math)3
Remainder, truncated (C, Java, JavaScript %)-2
Floored quotient-4

Worked out in your browser. Nothing you type is sent to a server.

How we worked it out

Updated as you change the numbers.

  1. Floored: r = a − n × ⌊a ÷ n⌋. Truncated: r = a − n × trunc(a ÷ n).

Method and assumptions

Both conventions agree for positive numbers. Floored modulo is what clock arithmetic and most math texts use.

Questions

What is −17 mod 5?

3 (math convention); JavaScript’s −17 % 5 gives −2.

Sources

Method and figures checked on . Every worked answer on this page is covered by an automated test. Found a mistake? Tell us.

Embed this calculator on your site

Free to use. Paste this where you want the calculator; it runs in your visitors’ browsers, sets no cookies and sends nothing to us.

Related calculators