Math
Remainder Calculator
Compute the remainder of dividend / divisor with both truncated (JavaScript, C) and floored (Python) conventions. Handles negatives and decimals.
Compute the remainder of dividend / divisor
The number being divided. Can be negative or decimal.
The number you are dividing by. Must not be zero.
Quotient rounds toward zero. Remainder takes the sign of the dividend.
Remainder (truncated)
-1
-7 = -2 * 3 + -1
Quotient
-2
trunc(a / b)
Decimal division
-2.333333
a / b
Floored (Python) remainder
2
quotient -3
Floored (Python) convention
-7 = -3 * 3 + 2
Both conventions satisfy the identity dividend = quotient * divisor + remainder. They only differ when dividend and divisor have opposite signs.
Frequently Asked Questions about the Remainder Calculator
What is a remainder in division?
The remainder is what is left over after dividing one whole number by another. For 17 / 5, the quotient is 3 and the remainder is 2, because 17 = 3 x 5 + 2. The same identity, dividend = quotient x divisor + remainder, works for negative and decimal inputs too, which is why every result here also shows the matching equation.
What is the difference between truncated and floored remainder?
Both conventions satisfy dividend = quotient x divisor + remainder. They only disagree when the dividend and divisor have opposite signs. Truncated rounds the quotient toward zero, so the remainder takes the sign of the dividend. Floored rounds the quotient toward negative infinity, so the remainder takes the sign of the divisor. For -7 / 3, truncated gives quotient -2 and remainder -1; floored gives quotient -3 and remainder 2.
Why does my code give a different remainder than this calculator?
Languages disagree on the convention for negative inputs. JavaScript, C, C++, Java, Go, Rust, and Swift use truncated remainder, so their % operator follows the sign of the dividend. Python, Ruby, and Haskell use floored remainder, so their % follows the sign of the divisor. Pick the matching convention in the toggle above and the calculator will reproduce your language's behavior exactly.
Can the divisor be zero?
No. Division by zero is undefined, so the calculator returns no result when the divisor is 0. Use any non-zero number, positive or negative, integer or decimal.
Does this work for decimal numbers?
Yes. The remainder of 7.5 / 2 is 1.5, because 7.5 = 3 x 2 + 1.5. The calculator handles any finite decimal dividend and divisor, rounds the displayed remainder to 6 decimal places, and shows the exact decimal value of dividend / divisor next to the quotient.