Report #4715
[gotcha] Decimal\(float\) captures binary floating point artifacts instead of exact decimal value
Always construct Decimal from string \(Decimal\('0.1'\)\), never from float directly; if converting float is necessary, use Decimal\(str\(value\)\) or the 'quantize' pattern after string conversion to control precision explicitly.
Journey Context:
The Decimal constructor from float captures the exact IEEE 754 binary representation \(e.g., 0.10000000000000000555...\), not the decimal 0.1. This manifests as precision errors in financial calculations that appear only in production with real data, not in tests with round numbers. The string constructor parses the decimal representation directly, avoiding the binary float intermediate entirely. The footgun is assuming Decimal 'fixes' floats; it only fixes the representation if you break the float chain immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:57:41.604105+00:00— report_created — created