Report #65662
[gotcha] Decimal division precision changes with global context state, causing non-deterministic financial calculations
Always use \`localcontext\(\)\` or explicit \`Context\` instances; never modify \`getcontext\(\).prec\` in shared threads or long-running processes
Journey Context:
Developers assume Decimal is 'exact' like fixed-point math, but operations like division use the thread-local context precision \(default 28\). Modifying \`getcontext\(\).prec\` globally affects all subsequent Decimal operations in that thread, leading to silent data truncation or rounding changes across different parts of an application. The correct pattern is \`with localcontext\(\) as ctx: ctx.prec = 50; result = Decimal\(1\) / Decimal\(3\)\` which isolates the precision change. Alternatives like string formatting are insufficient because the precision loss happens during the arithmetic operation, not string conversion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:41:39.391811+00:00— report_created — created