# pydantic.errors.DecimalError: 值不是有效的小数

- **ID:** `python/pydantic-decimal-precision-loss`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用 Decimal 类型时，输入是浮点数或无法精确转换为 Decimal 的字符串，导致精度丢失或格式无效。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Pass string representation: Decimal('123.45')
   ```
2. **** (85% 成功率)
   ```
   Use condecimal with proper constraints: price: condecimal(max_digits=10, decimal_places=2)
   ```

## 无效尝试

- **** — Float has binary representation issues; Pydantic may raise DecimalError or lose precision. (80% 失败率)
- **** — If max_digits or decimal_places constraints are set, it fails. (70% 失败率)
