# AssertionError: assert 0.1 + 0.2 == 0.3 (pytest.approx used incorrectly)

- **ID:** `python/pytest-approx-float-comparison-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Floating point arithmetic leads to precision issues; using '==' directly fails, and pytest.approx must be applied to both sides or used as a context.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## Workarounds

1. **Use pytest.approx to compare floating point values within tolerance.** (95% success)
   ```
   assert 0.1 + 0.2 == pytest.approx(0.3)
   ```
2. **Specify relative tolerance using pytest.approx with rel parameter.** (90% success)
   ```
   assert result == pytest.approx(expected, rel=1e-9)
   ```

## Dead Ends

- **Using round() on both values to compare** — Rounding can still introduce errors if the rounding precision is not chosen carefully. (60% fail)
- **Comparing with == after converting to Decimal** — Decimal conversion may not be accurate if the original values are floats. (50% fail)
