# java.lang.ArithmeticException: / by zero

**Code:** `ArithmeticException` · **Category:** Java · **Seen on:** Java

Integer division or modulo by zero.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/java/arithmeticexception-by-zero)
