Input
Result
Enter values and press Calculate to see the result here.
Example Data
Use these examples to understand sign conventions and Euclidean vs truncated remainders.
| Dividend (a) | Divisor (b) | Euclidean (q, r) | Truncated (q, r) |
|---|---|---|---|
| -13 | 5 | (-3, 2) | (-2, -3) |
| 20 | 6 | (3, 2) | (3, 2) |
| 7 | -3 | (-2, 1) | (-2, 1) |
| 123 | 10 | (12, 3) | (12, 3) |
Comparison: Euclidean vs Truncated (More Samples)
Additional pairs showing how remainders differ with signs and decimals.
| a | b | qeuclid | reuclid | qtrunc | rtrunc | a/b (exact, 4dp) |
|---|---|---|---|---|---|---|
| -25 | 4 | -7 | 3 | -6 | -1 | -6.2500 |
| 25 | -4 | -6 | 1 | -6 | 1 | -6.2500 |
| -25 | -4 | 7 | 3 | 6 | -1 | 6.2500 |
| 10.5 | 3 | 3 | 1.5 | 3 | 1.5 | 3.5000 |
| -10.5 | 3 | -4 | 1.5 | -3 | -1.5 | -3.5000 |
| 7.2 | -2.5 | -2 | 2.2 | -2 | 2.2 | -2.8800 |
Language Modulo Behavior (Quick Reference)
Typical defaults; always verify specific versions and flags for your environment.
| Language | Division rule for % | Remainder sign when b > 0 | Example: -13 % 5 |
|---|---|---|---|
| PHP | Truncates toward zero | Same as dividend (may be negative) | -3 |
| JavaScript | Truncates toward zero | Same as dividend (may be negative) | -3 |
| Java | Truncates toward zero | Same as dividend (may be negative) | -3 |
| C / C++ | Typically truncates toward zero | Same as dividend (may be negative) | -3 |
| Python | Floor division pair (// and % linked) | Always non‑negative if b > 0 | 2 |
Note: Many languages define a = bq + r, but choose different q (truncated vs floored). That choice determines the sign of r.
Formulas Used
- Truncated Division:
q = (int)(a / b),r = a − b × q. - Euclidean Division: find integers
qandrsuch thata = bq + rand0 ≤ r < |b|. - Relationship: The two conventions match when
a / b ≥ 0or whenr_trunc ≥ 0. - Exact Quotient:
a / b, rounded to your selected decimal places.
How to Use
- Enter Dividend (a) and Divisor (b). Avoid b = 0.
- Choose decimal places for the displayed exact quotient.
- Select the remainder convention you prefer to highlight in results.
- Tick Show steps for a concise derivation.
- Press Calculate. Export the results to CSV or PDF.
FAQs
a = bq + r with 0 ≤ r < |b|, regardless of signs of a or b.q = (int)(a/b) which truncates toward zero, so the remainder can be negative when a/b is negative.% operator behavior.