If you are building any kind of bookkeeping or khata (credit ledger) app, the first bug you will ship is a rounding bug. Here is what we learned building HisabOn, a digital ledger for small shops in Pakistan and the Gulf.

1. Never store money as a float

0.1 + 0.2 === 0.30000000000000004 in JavaScript. Multiply that across thousands of entries and a customer's balance drifts by a few paisa or fils. Store amounts as integers in the smallest unit (paisa for PKR, fils for AED) and only format at display time:

const toMinor = (amount, decimals = 2) => Math.round(Number(amount) * 10 ** decimals); const fromMinor = (minor, decimals = 2) => (minor / 10 ** decimals).toFixed(decimals); 

In the database use BIGINT (or NUMERIC(14,2) if you must keep decimals), never FLOAT/REAL.

2. Balances are derived, not edited

Keep an append-only table of entries (credit / debit, amount, customer, timestamp) and compute the balance as a sum. If a shopkeeper makes a mistake, add a correcting entry instead of editing the old one. This gives you an audit trail for free and makes sync conflicts much easier to resolve.

SELECT customer_id, SUM(CASE WHEN type = 'credit' THEN amount ELSE -amount END) AS balance_minor FROM ledger_entries GROUP BY customer_id; 

3. Currency belongs to the account, not the app

A shop in Dubai and a shop in Lahore use the same app. Store a currency code (ISO 4217, e.g. PKR, AED, SAR) on each business and format with Intl.NumberFormat:

new Intl.NumberFormat('en-PK', { style: 'currency', currency: 'PKR' }).format(1250); new Intl.NumberFormat('ar-AE', { style: 'currency', currency: 'AED' }).format(1250); 

4. Offline first

Many small shops have patchy connectivity. Write entries locally with a client-generated UUID and sync later; because entries are append-only, merging is mostly just "insert if the id doesn't exist".

Wrap-up

Integers for money, append-only entries, per-account currency and offline-first sync cover most of the hard problems in a simple ledger. If you want to see how this looks in a real product, HisabOn is at hisabon.com.