Money, quantities and dates: decisions
For: team leads and anyone deciding how money, quantities and dates work. The decisions behind the "numbers and dates" track, the seven phases, and where each reader's page is.
Status, 2026-11-10: phase 1 is on dev. Phases 2 to 6 are committed on branch aj-display-formats in both repos (backend 3c44b704c, frontend d75c5c81), not pushed. Phase 7 and the follow-up items are built on top and not committed. No migration script has been applied to any real database.
The problem
Money, quantities and dates were each handled in many places, each in its own way. Amounts were added as floating-point numbers in the browser, so a bill could be off by 0.01. Quantities were double in Java, so stock of 0.1 + 0.2 was 0.30000000000000004. The browser's locale and clock decided how a figure and a date looked. A moment such as "created at" was stored as the shop's wall clock but labelled UTC, so every report needed a correction, and one missed correction gave the wrong day.
Decisions
| Area | Decision |
|---|---|
| Rounding | Half-up, away from zero, everywhere (Java HALF_UP, big.js in the browser) |
| Money on screen | Locale from the tax country (IN, MY, SG), symbol from the ISO currency; the server's figures are the source |
| Quantities | Stored as numeric(19,6), held as BigDecimal; the API carries a number |
| Decimals per unit | Each unit says 0 to 4 decimals. Counted units take whole numbers. The server refuses more |
| Browser maths | Money and quantity maths on Money (big.js), never on bare floats |
| Round off | A business setting: none, nearest 1, or nearest 0.05 for cash. The 0.05 rule applies only to a bill paid wholly in cash. Posted to a Round Off account |
| Currency decimals | From the currency (INR, MYR, SGD: 2). Only 0, 2 or 3 allowed |
| Moments | An Instant, true UTC in timestamptz, sent with Z; shown in the business zone |
| Business days | A LocalDate in a date column, sent as yyyy-MM-dd. The time of entry comes from created_on |
| Time zone | One business zone per tenant for now. Branch and user zones come later, when a business has branches in two zones |
| Enforcement | Every rule has a lint check that blocks a mistake, proved by planting one |
The seven phases
| Phase | What it did | Repos |
|---|---|---|
| 1. One formatting service | FormatUtil and the money, quantity, day, dateTime pipes; dates with Z read as real moments |
Frontend |
| 2. Exact quantities | Quantity columns to numeric(19,6), entities to BigDecimal |
Backend, database |
| 3. Decimals per unit | units.decimals, a server guard on every save, and a quantity input directive |
Both, database |
| 4. Exact browser maths | Money on big.js; safeRound removed |
Frontend |
| 5. Round off | The rule, the column, the Round Off account, the journal leg, and the print line | Both, database |
| 6. Currency decimals | Default from the currency; only 0, 2 or 3 | Both |
| 7. One time convention | Moments in true UTC, days as dates, one script per tenant | Both, database |
| Follow-up | Exact stock maths (no EPSILON), screens send days as yyyy-MM-dd, round off on thermal receipts |
Both |
Not done
- E-invoice and MyInvois round-off and date fields: there is no e-invoice code yet. When it is built, it must send the saved round off and the business day as they are.
- Branch and user time zones.
- The tests were written but not run; the track was not checked in a browser.
Pages for each reader
- Developers: Money and quantities: technical design and Dates and time zones: technical design
- Product and BA: Money, quantities and dates: business rules
- Shop users and administrators: Round off, currency decimals and unit decimals
- Support: Runbook: rounding, quantity and date questions
- Release: Runbook: release checks for the numbers and time release
No comments to display
No comments to display