Modulo Calculator
percent a mod b
The number being divided. Integers or decimals, positive or negative.
The modulus. Must be non-zero.
analytics Result
Sign follows dividend. Matches C, C++, Go, Java, JavaScript (%).
tips_and_updates Tips
- • Use math modulo (floored) for modular arithmetic, hashing, and angle wrapping
- • Use C-style modulo (truncated) when matching behavior of C, C++, Go, Java, or JavaScript
- • For positive a and b the two conventions agree, so the distinction only matters with negatives
- • Modulo by zero is undefined — the divisor must be non-zero
- • Python's % operator uses math (floored) modulo: -7 % 3 = 2
The Formula
Math modulo uses floor division so the remainder is always 0 <= r < |b|. C-style modulo uses truncated division so the remainder has the same sign as the dividend.
r = a - b * q, where q = floor(a/b) (math) or trunc(a/b) (C-style)
lightbulb Variables Explained
- a Dividend (the number being divided)
- b Divisor (the modulus)
- q Quotient (floored or truncated)
- r Remainder / modulo result
tips_and_updates Pro Tips
Use math modulo (floored) for modular arithmetic, hashing, and angle wrapping
Use C-style modulo (truncated) when matching behavior of C, C++, Go, Java, or JavaScript
For positive a and b the two conventions agree, so the distinction only matters with negatives
Modulo by zero is undefined — the divisor must be non-zero
Python's % operator uses math (floored) modulo: -7 % 3 = 2
Frequently Asked Questions
Related Tools
View all Math View all arrow_forwardTags
Data sourced from trusted institutions
All formulas verified against official standards.