Repository navigation
fix(charges): round percentage fees exactly - #1118
Conversation
Remove the IEEE-754 floating-point fast path in percentageMinorUnits so percentage charge calculations always use exact decimal-string/BigInt half-up arithmetic. Format touched files with oxfmt per the check-changed-format CI gate. Fixes #1068
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe change adds unit and API test coverage for percentage rounding, charge validation, and charge behavior across orders and bills. The shared charge calculation code is reformatted. Its reported behavior and public declarations are unchanged. ChangesCharge calculation and API coverage
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to
|
|
Add Carrot credits or activate Agent usage billing to use Autofix |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Fixes #1068
Intent
Implement the surgical fix for FreeOpenSourcePOS/FloCafe issue #1068 ("Percentage charge calculation rounds half-cent down due to floating-point fast path"): remove the IEEE-754 floating-point fast path (
basisMinor * percentage) inshared/charges.tsso percentage charge calculations always use the existing exact decimal-string/BigInt half-up arithmetic (e.g., subtotal29725.00at65.74%rounds to19541.22instead of19541.21). Deliver via theno-mistakespipeline as its own PR (Fixes #1068).What Changed
basisMinor * percentage) frompercentageMinorUnitsinshared/charges.tsso all percentage charge calculations evaluate through exact decimal-string andBigInthalf-up rounding.tests/charges-calculation.test.tscovering half-minor-unit rounding boundaries, multi-decimal and scientific-notation rates, and zero/three-decimal currencies (JPY,KWD).tests/charges-engine-api.test.tsverifying end-to-end order, bill, and persistedcharges_breakdownrounding at exact half-cent boundaries (29725.00at65.74%->19541.22).Risk Assessment
✅ Low: The change removes the IEEE-754 floating-point fast path in percentageMinorUnits so all percentage charge calculations use the existing exact BigInt half-up arithmetic, backed by unit and API integration tests.
Testing
Ran
npm run test:charges(63/63 checks passing) andnpm run test:charges-engine(196/196 checks passing), and drove a live Express API and disposable SQLite instance to verify that configuring a 65.74% charge on a 29725.00 order and generating a bill computes and persists 19541.22 (total 49266.22), preserves historical bill snapshots after rate changes, and rounds half-minor-unit ties half-up across 0-, 2-, and 3-decimal currencies; this backend calculation fix has no UI surface change.Evidence: Live Express API and SQLite verification for #1068 half-cent percentage charge rounding
{ "configuredChargesStatus": 200, "configuredChargeRate": 65.74, "orderCreatedStatus": 201, "orderSubtotal": 29725, "orderServiceCharge": 19541.22, "orderTotal": 49266.22, "billGeneratedStatus": 201, "billServiceCharge": 19541.22, "billTotal": 49266.22, "billBalance": 49266.22, "subsequentOrderServiceChargeAt10Percent": 2972.5, "persistedDbOrder": { "id": 1, "subtotal": 29725, "service_charge": 19541.22, "total": 49266.22, "charges_breakdown": "[{"id":"service_charge","name":"Service Charge","type":"percentage","amount":19541.22,"calculation_basis":"gross","waived":false,"tax_category_id":null,"rate":65.74}]" }, "persistedDbBillAfterLaterRateChange": { "id": 1, "subtotal": 29725, "service_charge": 19541.22, "total": 49266.22, "balance": 49266.22, "charges_breakdown": "[{"id":"service_charge","name":"Service Charge","type":"percentage","amount":19541.22,"calculation_basis":"gross","waived":false,"tax_category_id":null,"rate":65.74}]" }, "boundaryMatrix": { "usdHalfCentFloatTrap": 19541.22, "jpyZeroDecimalHalfUnit": 1954122, "kwdThreeDecimalHalfUnit": 1954.122, "scientificNotationBoundary": [ { "id": "sci_below", "amount": 0 }, { "id": "sci_half", "amount": 0.01 }, { "id": "sci_above", "amount": 0.01 } ] } }Evidence: Charges calculation test suite output (63/63 passed)
Evidence: Charges engine API integration test suite output (196/196 passed)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run test:charges(63/63 checks passed intests/charges-calculation.test.ts)npm run test:charges-engine(196/196 checks passed intests/charges-engine-api.test.ts)Live Express API + SQLite verification (PUT /api/settings/charges,POST /api/orders,POST /api/bills/generate, and SQLiteorders/billsinspection) captured in~/.no-mistakes/evidence/01M4V9WHBMFA5A434JG1WHJXTN/live-api-verification.json✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Summary by CodeRabbit