# CSV float precision loss when reading/writing with pandas read_csv

- **ID:** `data/csv-float-precision-loss`
- **Domain:** data
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

pandas read_csv by default uses float64 which truncates float values beyond 15-17 significant digits, causing silent precision loss for high-precision data like scientific measurements or financial transactions.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| pandas 1.5.3 | active | — | — |
| pandas 2.0.0 | active | — | — |
| pandas 2.1.0 | active | — | — |

## Workarounds

1. **Use pandas.read_csv with dtype=Decimal for critical columns: `import decimal; df = pd.read_csv('data.csv', dtype={'amount': decimal.Decimal})`** (90% success)
   ```
   Use pandas.read_csv with dtype=Decimal for critical columns: `import decimal; df = pd.read_csv('data.csv', dtype={'amount': decimal.Decimal})`
   ```
2. **Read CSV as string and convert to Decimal after: `df = pd.read_csv('data.csv', dtype=str); from decimal import Decimal; df['amount'] = df['amount'].apply(Decimal)`** (88% success)
   ```
   Read CSV as string and convert to Decimal after: `df = pd.read_csv('data.csv', dtype=str); from decimal import Decimal; df['amount'] = df['amount'].apply(Decimal)`
   ```
3. **Use numpy.float128 if available: `df = pd.read_csv('data.csv', dtype={'amount': np.float128})`** (75% success)
   ```
   Use numpy.float128 if available: `df = pd.read_csv('data.csv', dtype={'amount': np.float128})`
   ```

## Dead Ends

- **** — This disables all numeric processing and may break downstream operations expecting float types; also increases memory usage significantly. (60% fail)
- **** — Rounding cannot recover lost precision; the original value is already truncated during CSV parsing. (90% fail)
- **** — float64 is the default and still truncates; need higher precision type like float128 or decimal. (80% fail)
