Menu

Money in a Rails quote-to-invoice app: integer cents, one rounding rule, and a browser total that doesn't count
📰

Money in a Rails quote-to-invoice app: integer cents, one rounding rule, and a browser total that doesn't count

DEV Community: ruby·Anton Chisliuk·1 day ago
#8aYyo7uN
#devtoruby#devto#dev#total#line
Long article (1830 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: this article was created with the help of AI. AI tools drafted it from my codebase and project notes, and I edited it and checked it against the code before publishing. I'm the founder of the app it describes.

I'm building an estimate and invoice app for small trade businesses, crews of one to five people. The contractor writes an estimate, the customer opens a link, picks an option, signs and pays a deposit. Later the same numbers become an invoice.

So one price shows up in a lot of places: the editor, the customer's page, the PDF, the email, the signature record and the invoice. If two of them disagree by one cent, the customer has a reason to doubt the rest. This post is about how money works in that Rails 8 app: how it's stored, where it gets rounded, how tax and deposits are calculated, and why the total the browser shows doesn't count.

Integer cents and a currency code

Every amount in the database is an integer column that ends in _cents . The currency is its own column on the document.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.