Skip to main content

MATH · MODULO

Modulo Calculator

Calculate the remainder of a division (modulo) for any integers, including negatives. Choose between truncated (JavaScript/C) and floored (Python) convention.

Operands

−7 % 3 = −1 (remainder has same sign as dividend)

01 Remainder
1
7 ÷ 3 = 2 remainder 1
02 Quotient
2
Identity check: 7 = 2 × 3 + 1

About This Calculator

The modulo operation finds the remainder after integer division. This calculator supports both common conventions for negative operands: truncated (JavaScript, C, Java) where the remainder has the same sign as the dividend, and floored (Python, Ruby) where the remainder has the same sign as the divisor.

How It Works

Enter the dividend (a) and divisor (n), then choose your convention. The calculator shows the quotient, remainder, and verifies the identity a = quotient × divisor + remainder. For positive operands both conventions give the same result. They differ only when one or both operands are negative.

The Formula

Truncated: a % n = a − trunc(a/n) × n Floored: a mod n = a − floor(a/n) × n

a
dividend (the number being divided)
n
divisor (the number to divide by)

Frequently Asked Questions

What is the difference between truncated and floored modulo?
They differ only for negative operands. Truncated mod (JavaScript's %) rounds the quotient toward zero, so the remainder has the same sign as the dividend. Floored mod (Python's %) rounds the quotient toward negative infinity, so the remainder has the same sign as the divisor. For positive operands they are identical.
What is -7 mod 3?
It depends on the convention. Truncated (JavaScript): −7 % 3 = −1 (quotient is −2; check: −2 × 3 + (−1) = −7 ✓). Floored (Python): −7 mod 3 = 2 (quotient is −3; check: −3 × 3 + 2 = −7 ✓).
What is modulo used for?
Modulo is used to check if a number is even or odd (n % 2 = 0 means even), to wrap values in a cyclic range (e.g. clock arithmetic: hour % 12), to find if one number divides another evenly, and in cryptography and hashing algorithms.
Can I use decimals with modulo?
Mathematically yes. 5.5 % 2 = 1.5 (5.5 = 2 × 2 + 1.5). The identity a = quotient × divisor + remainder still holds.