Modulo Calculator
Compute the quotient and remainder of a ÷ b, with truncated, floored, and Euclidean modulo conventions for handling negative numbers.
Sign matches the dividend (JavaScript % operator)
- 1
Quotient (rounded toward zero)
trunc(17 ÷ 5) = 3 - 2
Truncated remainder
17 − 5 × 3 = 2Sign follows the dividend — this matches the JavaScript % operator.
How does this calculator work?
The modulo of a ÷ b is the remainder left after division. With q = trunc(a/b), the truncated remainder is a − b·q (sign of a). Floored and Euclidean variants change the quotient rounding so the remainder follows the divisor or stays non-negative — important only when a or b is negative.
Formula
How this is calculated
Enter the dividend a (the number being divided) and the divisor b (the number you divide by). The divisor cannot be zero, since division by zero is undefined and the calculator returns no result in that case.
The quotient is q = trunc(a / b), rounding toward zero. The truncated remainder rT = a − b·q is what most programming languages (and the JavaScript % operator) produce: its sign follows the dividend a. The floored remainder rF = a − b·floor(a / b) follows the sign of the divisor b, which is the convention used by Python's % and modular arithmetic. The Euclidean remainder rE = a − b·floor(a / |b|) is always non-negative (0 ≤ rE < |b|), which is preferred in number theory.
For positive a and b all three remainders are identical. They differ only when a or b is negative. Inputs may be any real numbers — fractional values are allowed and the same formulas apply, though modulo is most commonly used with integers.
Frequently asked questions
They use different rounding rules for the quotient. Truncated rounds toward zero (C/JavaScript), floored rounds toward negative infinity (Python), and Euclidean always yields a non-negative remainder. For positive inputs they all agree.
Division by zero is undefined, so the calculator shows a warning and returns no result. Choose a non-zero divisor.
JavaScript, C, C++, Java and Go use the truncated remainder (sign of the dividend). Python and Ruby use the floored remainder (sign of the divisor).
Also known as
TG we-Calculate Editorial Team. (2026). Modulo Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/modulo-calculator
TG we-Calculate Editorial Team. "Modulo Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/modulo-calculator.
TG we-Calculate Editorial Team, "Modulo Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/modulo-calculator
@misc{wecalculate_modulo_calculator, title = {Modulo Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/modulo-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
