How this calculator works
Whole-number division produces two results: how many whole times the divisor fits (the quotient) and what is left over (the remainder). The two rules differ only for negative dividends. Truncating division rounds the exact quotient toward zero, so the remainder takes the sign of the dividend. Floor division rounds toward minus infinity, so a negative dividend gives a positive remainder against a positive divisor. Both rules satisfy dividend = divisor × quotient + remainder.
Formula
a = b × q + r. Truncating rule: q = trunc(a/b) and r = a - bq, with |r| < |b|. Floor rule: q = floor(a/b) and r = a - bq, with 0 ≤ r < |b| when b > 0.
Worked example
17 ÷ 5 gives q = 3 and r = 2 under both rules, because 17 = 5 × 3 + 2. For -17 ÷ 5, truncating gives q = -3 and r = -2, while floor division gives q = -4 and r = 3.
Advertisement
Frequently asked questions
Which rule do calculators and programming languages use?
Most calculators and the C, Java and JavaScript integer operators truncate toward zero. Python, Ruby and many mathematical texts floor instead. Neither is wrong, but the two rules disagree whenever the dividend is negative.
What is the difference between a quotient and a fraction?
The quotient is the whole-number part of the division. The decimal result divides exactly and can include a fractional part, such as 17 ÷ 5 = 3.4.
Why is a zero divisor rejected?
Division by zero has no answer: no number multiplied by zero gives a nonzero dividend, and every number multiplied by zero gives zero. The equation a = bq + r has no solution when b = 0 and a ≠ 0.