Report #4378
[gotcha] decimal.Decimal\(float\_literal\) silently creates inexact values from binary float representation
Never pass float literals or float variables to Decimal\(\). Always pass strings, integers, or tuples: Decimal\('0.1'\) or Decimal\(1\) / Decimal\(10\). If you must convert a float that came from external data, use Decimal.from\_float\(\) to explicitly acknowledge the binary representation, then quantize.
Journey Context:
Decimal is designed for base-10 exact arithmetic. However, the constructor accepts float, and Python's float is binary IEEE 754. When you write Decimal\(0.1\), the float 0.1 is already the approximation 0.10000000000000000555... Decimal then stores that exact value, defeating the purpose of using Decimal for precision. This is a silent data corruption bug in financial calculations. The documentation explicitly warns against this, but the API design \(accepting float\) makes it an easy trap. The fix is discipline: treat Decimal like a text-parsing tool, not a numeric converter.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:19:07.742245+00:00— report_created — created