gjin@prishtina/writing

Money in whole cents: the rules behind Tally

Floating point, locale formatting and a typo saved as zero are how money apps lie. The rules Tally, a SwiftUI and SwiftData budget app, follows so every number adds up.

Tally is a small Mac app for one person’s monthly money. Its whole job is one honest number: what you can spend today. Getting that number right comes down to a handful of rules, and none of them are about SwiftUI.

1. Money is an integer

Every amount is whole cents in an Int, never a Double. Floating point can’t represent 0.10 exactly, and an app that adds a month of coffees in binary fractions will eventually be a cent off. A cent off is a bug report that says “your app can’t count”.

Money logic lives in one folder, as plain values with no UI and no database in it. Everything else asks it questions.

2. Format by hand, not by locale

Tally shows amounts as 2 450,17 €: groups of three split by a non-breaking space, comma decimals, a non-breaking space before the euro sign, and a real minus sign for negatives.

That’s written by hand instead of with the system’s number formatter, on purpose. A formatter follows the Mac’s region settings, so the same app would show different numbers to the same person after they changed a setting. Money should look the same every time you open it.

3. A typo is refused, never saved as zero

Parsing accepts the ways people actually type amounts: 12,5, 12.50, 12, 2 400. It refuses letters, empty text and more than two decimals. The rule behind it: a typo must never be saved as 0. A zero that should have been 120 is worse than an error, because nobody notices it.

Balances can be typed negative (an overdrawn account, a card in credit), and only fields that mean a balance accept a minus.

4. Round toward safety

The daily allowance is what’s left in the main account, minus everything still due before the next income, divided by the days until that income. The division rounds down, also for negatives. The allowance can be negative, and it’s never hidden, but it is never more than the money allows.

5. Let the model read, never write

Tally has an Ask box: “where did my money go this week?”. It uses Apple’s on-device model, and the model’s only job is to turn the question into a structured query: a topic, a period, maybe a category or a person. The answer is computed by exact, tested code, and the model never writes a sentence about your money.

A language model is good at understanding what you meant. It shouldn’t be the thing doing your arithmetic.

6. Never lose what someone saved

Every change to the stored data is a versioned schema with a migration, and each one has a test that opens a file saved the old way. An app that opens empty after an update has lost someone’s money history, even if the file is still on disk. Tally also never falls back to a fresh store when the real one can’t be read: it says so instead.

The rest follows

No network, no third-party packages, and nothing moves while the app is idle, so it sits at about 0% CPU. Each of those is one less way for a money app to surprise you.

All notes