The direct answer

Compare a reservation’s full admitted amount with its ceiling before producing a shortened display. Decimal input can be exact while later arithmetic still rounds, so define operand bounds, an explicit calculation context and failure handling. Correct arithmetic remains separate from current allowance, atomic reservation and permission to dispatch.

Resolve the arithmetic question before the ledger question

A budget screen shows a short cost estimate, while the dispatcher needs an amount to reserve. Reusing the display value can admit a proposal whose full amount exceeds the remaining allowance. Changing the numeric type alone does not specify which operations may lose digits.

The reservation guide covers shared holds and uncertain usage. The JSON guide preserves number spelling and demonstrates integer minor units. This worksheet starts after input admission and selects a different, fractional arithmetic contract. It does not recommend replacing a supported integer-unit design.

Select a bounded calculation, not unlimited decimal input

The opened Python reference identifies version 3.15.2. Decimal construction retains input digits; arithmetic uses context precision. A float conversion preserves the float’s value, not an intended decimal spelling. Context signals can set sticky flags and trigger enabled traps.

Our proposed application accepts one to eight charge lines. Each rate is an already-admitted ASCII string from 0.000000 through 999.999999, with exactly six fractional digits and no sign, exponent or leading-zero repair. Each count is a trusted integer from 1 through 999999, excluding booleans. The ceiling uses the same six-place scale, from 0.000000 through 9999999999.999999. Every amount has the same invented unit.

Construct amounts only from these admitted strings and counts from admitted integers. Exclude floats, special values, alternative constructors and implicit coercion. This is an application restriction; a numeric constructor accepting something is not our admission certificate.

Prove the precision envelope and own the context

Multiply each rate by its count, then add the products starting from six-place zero. A rate has at most nine coefficient digits; a count has six. A product therefore needs at most fifteen digits, and summing eight products needs at most sixteen at the common six-place scale. The ceiling also needs at most sixteen. This is elementary reasoning about the fictional bounds, not an executed arithmetic test.

Choose precision 20, Emin −20, Emax 20, clamp 0 and ROUND_HALF_EVEN. Explicitly enable every documented signal trap for the calculation. Reject an exception or any unexpected signal; never continue with a partial total. The margin is specific to this multiply-and-add plan. Division, discounts, negative adjustments, additional lines or different scales require a new proof.

The reference’s localcontext contract copies the supplied context on entry and restores the previous one on exit. Omitted Context fields can inherit defaults; flags require clearing. Our adapter must supply the complete reviewed policy, clear flags immediately before each calculation, inspect them before leaving, and exclude callbacks or suspension inside this synchronous operation. Actual adapter and runtime support remain unestablished.

Preserve the decision amount; derive the display separately

Invent three units at rate 0.125000 demo credits. Their total is 0.375000; a ceiling of 0.400000 permits a conditional reservation check. These are invented units and worksheet mathematics, not provider prices, savings or observed billing.

The useful counterexample changes the rate to 0.124999 and the ceiling to 0.374000. Three units total 0.374997, which exceeds that ceiling. A two-place display of 0.37 could appear affordable. The admitted total must reject the proposal regardless of that display.

quantize rounds to a selected exponent. Our separate display policy uses exponent −2 and ROUND_HALF_EVEN, in its own fresh context: precision 20, Emin −20, Emax 20, clamp 0, with all signal traps enabled except intentionally permitted Rounded/Inexact. Label the display approximate. Never replace the retained six-place decision amount, reuse display flags as calculation evidence, or send the display amount to the reservation store.

Also prohibit further context-sensitive arithmetic or normalization between calculation and handoff. Preserve the exact admitted amount and unit through a separately supported serialization contract. A downstream binary-number conversion invalidates this selected handoff.

Review eight inert admission cards

All cards are PROPOSED_UNRUN. They describe proposed adapter behavior; no Decimal objects, contexts or calculations were executed.

CardConditionProposed disposition
1. Ordinary positiveThree at 0.125000; ceiling 0.400000; all prerequisites established.Retain 0.375000 for an atomic reservation check, not automatic dispatch.
2. Rounded display fitsThree at 0.124999; ceiling 0.374000; display 0.37.Reject full total 0.374997 as over limit.
3. Approximate inputA float or already-rounded amount replaces admitted text.Reject this path; missing digits cannot be reconstructed.
4. Envelope exceededNinth line, oversized count or changed scale.Reject before calculation; no implicit precision increase.
5. Arithmetic signalCalculation traps or reports unexpected rounding.Hold without publishing a partial reservation.
6. Inherited flagsPer-calculation flag reset or attribution is unknown.No clean arithmetic evidence; hold.
7. Invalid domainNonfinite, negative or different-unit operand.Reject the data contract, independently of comparison behavior.
8. Changed handoffConsumer loses precision or allowance changes before reservation.Hold until exact handoff and current shared allowance are established.

Keep exact calculation inside its actual authority

A positive requires an independently supported runtime, trusted bounded inputs, reviewed arithmetic adapter, exact handoff, current unit/rate policy and atomic shared reservation. They are unimplemented or unknown here, so no real proposal is admitted. Arithmetic cannot establish usage completeness, unknown-charge reconciliation, model permission or an ultimate spend ceiling.

No Decimal import, numeric-context construction, arithmetic experiment, model, billing, payment or account operation was performed for these cases. Only documentation research and editorial writing occurred. Boundary remains prelaunch with planned request-path checks; its separate mock policy evidence does not implement or validate this arithmetic adapter.

Primary sources

Official references supporting the guidance. Examples in this guide are synthetic and are not reports of a production incident.

  1. Python 3.15 decimal reference — observed 3.15.2