Method and source check
Last checked:
Automated source and implementation review, including worked examples and documented numerical limits. This review does not provide professional advice or specialist approval.
Method
Divide the entered dividend by a nonzero divisor. Show the decimal answer, a quotient truncated toward zero, and the JavaScript remainder of the same inputs.
decimal answer = dividend / divisor
truncated quotient = trunc(dividend / divisor)
remainder = dividend % divisor
Variables and units
- dividend
- number being divided; unitless input
- divisor
- nonzero number used to divide; unitless input
- remainder
- leftover relative to the truncated quotient; has the dividend's sign
Worked example
For 17 ÷ 5, the decimal answer is 3.4, the truncated quotient is 3, and the remainder is 2 because 17 = 5 × 3 + 2.
Limitations
The decimal answer is rounded to at most six decimal places when multiplying it by 1,000,000 remains finite; otherwise the finite answer is shown without that rounding. The truncated quotient and remainder are not decimal-rounded.
- The divisor cannot be zero, and a result that overflows the number range is rejected.
- Both inputs can be negative or fractional. A negative dividend produces a negative remainder; the remainder may be fractional. This is a remainder, not a nonnegative modulo result.
- The calculator uses JavaScript floating-point numbers. Very small nonzero answers may display as 0 after rounding, and fractional remainders may show small precision effects.
- 17 ÷ 5: quotient 3, remainder 2, decimal 3.4.
- −17 ÷ 5: quotient −3, remainder −2, decimal −3.4.
- 5.5 ÷ 2: quotient 2, remainder 1.5, decimal 2.75.
- 1 ÷ 3: quotient 0, remainder 1, displayed decimal 0.333333.
- 0 ÷ 5: all displayed results 0; division by zero rejected.