# AssertionError: assert 0.1 + 0.2 == 0.3
 +  where 0.1 + 0.2 = 0.30000000000000004

- **ID:** `python/pytest-approx-comparison-fail`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Floating-point arithmetic precision issues cause the sum of 0.1 and 0.2 to be slightly off from 0.3, leading to a failed equality assertion.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.0.0 | active | — | — |
| 8.0.0 | active | — | — |

## Workarounds

1. **Use pytest.approx for floating-point comparisons** (95% success)
   ```
   from pytest import approx
assert 0.1 + 0.2 == approx(0.3)
This uses a default relative tolerance of 1e-6.
   ```
2. **Specify a custom tolerance with approx** (90% success)
   ```
   assert 0.1 + 0.2 == approx(0.3, rel=1e-9, abs=1e-12)
This allows fine-grained control over the comparison.
   ```

## Dead Ends

- **Rounding the result to a fixed number of decimal places** — This may mask real precision issues in other calculations and is not a general solution. (60% fail)
- **Using assert 0.1 + 0.2 == 0.3 with a tolerance check manually** — This is error-prone and less readable than using pytest.approx. (40% fail)
