Report #13313
[gotcha] Decimal constructor from float creates high-precision binary artifact ignoring context
Never pass float literals or variables to Decimal\(\); always pass strings or use Decimal.from\_float\(\) explicitly, then quantize to desired precision.
Journey Context:
Decimal is designed for decimal arithmetic with configurable precision via the active context. However, Decimal\(0.1\) does not create a Decimal with value 0.1 and precision 1; instead, it converts the binary float 0.1 \(which is actually 0.10000000000000000555...\) into a Decimal with that exact long binary fraction. This conversion ignores the context precision entirely, creating a Decimal with 50\+ digits of noise. Only the string constructor Decimal\('0.1'\) parses the decimal representation directly. The fix is to treat Decimal\(float\) as a code smell; use strings for literals, or if converting computed floats, use Decimal.from\_float\(\) to explicitly acknowledge the binary conversion, then immediately quantize\(\) to strip artifacts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:21:38.231626+00:00— report_created — created