Computes cart line totals, discounts, taxes, and change using integer‑cent arithmetic to avoid floating‑point errors, supporting exclusive/inclusive tax and prorated order discounts.
// Source: https://github.com/HeyPuter/everything | License: MIT | Copyright 2026 Puter Technologies Inc // Provided via justclaw.it.com; keep this notice with the code. /** * Cart math. Everything is computed in integer cents so line totals, the * tax breakdown, and the grand total agree to the cent - no float drift, * no "subtotal + tax ≠ total" receipts. * * Discount model: * - a line discount applies to one line (percent of the line, or fixed); * - an order discount applies to the sum of discounted lines and is * prorated across them (largest-remainder) so per-line tax stays exact. * * Tax model: * - exclusive (default): tax is added on top of the discounted price; * - inclusive: prices already contain tax; the breakdown extracts the * tax portion without c ... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key