java.lang.ArithmeticException: / by zero
Integer division or modulo by zero.
Non-terminating decimal expansion Meaning
Integer division by zero throws; floating-point division returns Infinity/NaN instead. BigDecimal also throws for non-terminating decimals without a rounding mode.
Common causes
- Divisor is 0 (empty counts)
- BigDecimal.divide without scale/RoundingMode ("Non-terminating decimal expansion")
⚡ Quick fix
- Guard the divisor
- Use divide(x, 2, RoundingMode.HALF_UP) for BigDecimal
Detailed fix by platform
Java
BigDecimal avg = total.divide(BigDecimal.valueOf(n), 2, RoundingMode.HALF_UP);
How to diagnose
- Expression — Which division?
- Type — int or BigDecimal?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Java
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026