🧱
🧱 Building with the Larz Stack · STK-101 · Session 2 of 8

Money & Payments — Handling Money Correctly

Money is where sloppy code costs real cash. This family of the stack does money the right way: exact values, double-entry ledgers, real invoices, and subscription billing.

⏱ 9 min read📅 Updated 2026-07-26📊 Tables, charts & examples

The single most common money bug in software is using a floating-point number for currency — where 0.1 + 0.2 famously isn't 0.3. The Larz Stack's money family refuses to make that mistake, and builds up from there: exact money, books that always balance, professional invoices, and subscription logic you don't have to hand-roll.

📌 Worked example
The penny that breaks the books. An app stores prices as floats. A $9.99 subscription, times thousands of customers, times months of proration and refunds — and slowly the totals drift by cents, then dollars, until finance can't reconcile the ledger. The fix isn't heroic debugging; it's never using floats for money. larzmoney stores exact minor units and its split() always reconciles, so the drift can't start in the first place.

The money family

Four libraries cover most of what a money-handling app needs.

LibraryWhat it does
larzmoneyExact money as integer minor units + currency — never a float
larzledgerDouble-entry accounting: postings that must balance, trial balance
larzpdfGenerate real PDF invoices & receipts with exact, aligned totals
larzsubscriptionBilling state machine: trials, renewals, dunning, proration, cancel

Notice the layering: exact values (larzmoney) become entries in books (larzledger), documents (larzpdf), and recurring billing (larzsubscription).

Exact money in practice

larzmoney stores money as whole minor units (cents) with a currency, so arithmetic is always exact and splitting never loses or invents a penny.

from larzmoney import Money

bill = Money("100.00", "USD")
shares = bill.split(3)            # exact 3-way split
# [$33.34, $33.33, $33.33] — sums back to $100.00, no lost cent

Money("0.1","USD") + Money("0.2","USD")   # == $0.30 exactly
⚠️
Never store money as a float. Floats can't represent most decimal amounts exactly, so errors accumulate — a cent here, a cent there — until your books don't balance. Integer minor units (what larzmoney uses) are the standard correct approach, and its split() guarantees the parts always reconcile to the whole.

From values to a business

Stack the money libraries and you have a real billing backend.

NeedReach for
Charge exact amounts, split billslarzmoney
Keep books that always balancelarzledger
Send an invoice or receiptlarzpdf
Run monthly plans with trialslarzsubscription

Each is independent, but together they cover the money layer of most SaaS and marketplace apps — and all of it plugs into the Larz framework (Session 6).

🎯 Key takeaways

  • The money family: larzmoney (exact money), larzledger (double-entry), larzpdf (invoices), larzsubscription (billing).
  • larzmoney stores money as integer minor units — arithmetic is exact and split() always reconciles.
  • Never use floats for currency; rounding errors accumulate until books don't balance.
  • Layered together, these cover the money backend of most SaaS and marketplace apps.

Frequently asked

Why not just use Python's Decimal?

Decimal fixes float inaccuracy and larzmoney uses exact arithmetic under the hood, but money is more than a number — it has a currency, needs safe splitting/allocation that reconciles, formatting, and rounding rules. larzmoney wraps all of that into a money type that refuses invalid operations (like adding two different currencies), so the correctness is enforced, not left to you to remember.

Do these work with real payment providers?

The money libraries handle the money logic — exact amounts, ledgers, invoices, subscription state. Actually moving money happens through a payment provider, which the Larz framework's provider layer handles (Stripe, GemVault, crypto, etc.). You keep your money math exact and provider-agnostic, and swap the checkout backend without touching your billing logic.

Session 2 of 8 complete

Next up: Data & Storage — Persisting Without a Server

Continue to Session 3 →

Related lessons

More in this course

Course home → · Browse all courses →