Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Case Study: A Three-Line Cart Priced in Minor Units, Not Floats

说明与用途

案例研究展示了使用整数最小单位计价和严格的四舍五入规则,如何消除因浮点运算导致的发票中一分钱的差异。

问题

A cart priced with floating point arithmetic can drift by a cent, causing reconciliation errors with the ledger.

结果

The helper produces a deterministic total of 58.42 USD (5842 minor units) for the sample cart, preventing one-cent drift and ensuring finance reconciliation matches the invoice.

工作流

  • Freeze pricing rules and sample numbers in the repository before prompting an agent.
  • Write a helper module that defines currency scales, rounding, and validation.
  • Implement invoice_total to compute net, discount, tax, and total in minor units.
  • Create tests that assert the expected total of 5842 minor units for the sample cart.
  • Run tests locally and on a disposable server to verify consistency.
  • Review and reject any changes that alter the frozen rules or sample numbers.

证据

A three-line cart can look correct in a demo and still miss the ledger by one cent after tax.

来源

The expected USD total for the sample cart is 5842 minor units, which is 58.42 after the rules above.

来源

You want a pure function that prices one cart in integer minor units and fails closed when the currency scale is unknown.

来源

  • 记录日期: 2026-10-09T15:55:52.485Z