HomeMath › Modulo Calculator

Modulo Calculator

Divides one number by another and reports the remainder under the three common sign conventions (truncated as in C/JavaScript, floored as in Python, and the non-negative Euclidean modulo) together with the integer quotient.

When to use

You need a mod b, the remainder of a division, or want to know how different programming languages treat negative operands.

Do not use when: You need the prime factors or divisors of a number (use prime-factorization) or a change of number base (use base-converter).

Formula

truncated: r = a − b·trunc(a/b); floored: r = a − b·⌊a/b⌋; Euclidean: r = a − |b|·⌊a/|b|⌋ (0 ≤ r < |b|)

Inputs

ParameterTypeUnitRequiredDescription
dividendnumberyesThe number being divided. Integers are exact; decimals are allowed. Range: ≥ -1000000000000000, ≤ 1000000000000000
divisornumberyesThe number to divide by; must not be 0. Range: ≥ -1000000000000000, ≤ 1000000000000000

Outputs

OutputTypeUnitDescription
remaindernumbera − b × trunc(a / b): the % operator of C, Java and JavaScript.
quotientnumbertrunc(a / b), rounded toward zero.
floored_modulonumbera − b × ⌊a / b⌋: the % operator of Python and the mod of spreadsheets.
modulonumberThe mathematical residue in [0, |b|): a − |b| × ⌊a / |b|⌋.
is_divisiblebooleantrue when the remainder is 0.
expressionstringa = b × quotient + remainder with the truncated convention.

Example

17 mod 5: {"dividend":17,"divisor":5}{"remainder":2,"quotient":3,"floored_modulo":2,"modulo":2,"is_divisible":false,"expression":"17 = 5 × 3 + 2"}

−7 mod 3: {"dividend":-7,"divisor":3}{"remainder":-1,"quotient":-2,"floored_modulo":2,"modulo":2,"is_divisible":false}

GET https://tttkmbb.com/api/v1/calculate/modulo?dividend=17&divisor=5

Machine access

Sources

FAQ

Why does −7 mod 3 give both −1 and 2?

Languages disagree on the sign: C, Java and JavaScript return −1 (remainder takes the sign of the dividend), Python and Excel return 2 (sign of the divisor). The Euclidean modulo is always non-negative.

Does it work with decimals?

Yes, e.g. 7.5 mod 2 = 1.5. Because inputs are binary floating-point numbers, results like 0.3 mod 0.1 may show tiny rounding artefacts.

Related calculators