ArithmeticException Java Origin: Application & API OSI layer 7 · Application Last updated 13 Oct 2026

java.lang.ArithmeticException: / by zero

Integer division or modulo by zero.

Exact message you may see Non-terminating decimal expansion
Seen on: Java

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

  1. Guard the divisor
  2. Use divide(x, 2, RoundingMode.HALF_UP) for BigDecimal

Detailed fix by platform

Java

  1. BigDecimal avg = total.divide(BigDecimal.valueOf(n), 2, RoundingMode.HALF_UP);

How to diagnose

  1. Expression — Which division?
  2. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

1690 — MySQL ERROR 1690 (22003): BIGINT UNSIGNED value is out of range (MySQL)1690AccessDeniedException — java.nio.file.AccessDeniedException: /path (Java)AccessDeniedExceptionIllegalArgumentException — java.lang.IllegalArgumentException (Java)IllegalArgumentExcept…IllegalStateException — java.lang.IllegalStateException (Java)IllegalStateExceptionIndex was out of range — ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection (.NET)Index was out of rangeInputMismatchException — java.util.InputMismatchException (Scanner) (Java)InputMismatchExceptionNoSuchElementException — java.util.NoSuchElementException: No value present (Java)NoSuchElementExceptionrelease version not supported — [ERROR] Fatal error compiling: error: release version 17 not supported (Java)release version not s…Arithmeti…

Explore the map of this error Full error map →

🧠 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.