Splitting an amount to the cent without losing a dinar
Mehdi Messaoudene1 min readBusiness software and ERP

Management software must never lose a cent on the way. BiCharges calculates in whole cents and distributes remainders so the shares always add up to the total, credit notes included. BioRentabilité applies the same rigour to FIFO and weighted-average costs, with reproducible results.
- Amounts are integers (cents), never floats.
- Remainders of a split are distributed: the shares add up to the total.
- A credit note is split with the same rule as an invoice.
- FIFO and weighted-average costs recompute identically, at a fixed scale.
Why a float does not suit amounts
A price catalogue does not tolerate binary rounding. In Bio Réactifs, prices are already stored in cents: an integer, never a float. BiCharges, the expense-management software, takes that rule all the way: it can read and display cents, and every calculation runs on integers.
Splitting without losing the total
Dividing 100.00 into three shares does not give three times 33.33: one cent is left. BiCharges distributes the remainders so the shares always add up to the total. The same rule applies to a credit note, which avoids the few-cent gap that makes an accounting reconciliation fail.
Reproducible calculations
BioRentabilité computes the real profitability of an import: costs spread across lots, FIFO and weighted-average costs, recomputation when a figure changes. The calculations are deterministic and at a fixed scale: the same data always gives the same numbers, so they can be checked and compared from one recomputation to the next.
Takeaways
- Count in integers from data entry, not at display time.
- Decide once and for all where the remainder of a split goes.
- Test the edge cases: a credit note, an amount that does not divide, a full recomputation.
Frequently asked questions
Why avoid decimal numbers for money?
Because a binary float cannot represent most decimal amounts exactly: rounding errors accumulate. An integer number of cents does not cheat.
What happens to the remainder of a division?
It is distributed among the shares, so the original total is found again exactly. Nothing is lost or created.
Cet article existe aussi en anglais
Discussion
Comments use a GitHub account.


