<R/>

Crafting digital experiences

<R/>Rofiq.Full-Stack Product Engineer
AboutServicesWorkBlogRésuméContact
AboutServicesWorkBlogRésuméContact
Let's talk

One project slot open

Got something worth building? Let's make it real.

Start a project
<R/>Rofiq RahmanFull-Stack Product Engineer

Full-stack product engineering for teams that want the thing shipped, measured and maintainable.

Explore

AboutServicesWorkBlogRésuméContact

More

RésuméPrivacy policyUses — tools, hardware and setupRSS feed

Connect

© 2026 Rofiq Rahman. Crafted with Next.js.

Back to top
All articles

Backend

Storing money: integers, always

A short post about the one bug I refuse to debug twice, and the three places floating-point currency still sneaks into an otherwise careful codebase.

Mr. Rofiq Rahman · Aug 16, 2026 · 5 min read

Budgeting dashboard showing envelope budgets and a transaction list

0.1 + 0.2 === 0.30000000000000004. Everyone knows this. Everyone still ships a Float column called price at some point.

Store money as an integer in the smallest currency unit. 1,250 means ৳12.50. Convert once, at the edge, for display.

Where it still sneaks in

1. The percentage discount. subtotal * 0.85 gives you a float, and now you are rounding — and whether you round each line or the total changes the answer. Pick one, write it down, and put it in a function.

// Round half up, per line item, then sum. Documented because
// the finance team reconciles against this exact behaviour.
const discounted = (minorUnits: number, percent: number) =>
  Math.round((minorUnits * (100 - percent)) / 100);

2. The CSV import. Someone exports from a spreadsheet, the column is 12.50, and parseFloat is right there. Parse to minor units with a string-based conversion, and reject anything with more decimal places than the currency allows.

3. The chart library. It wants numbers and it will happily average your integers into a float. That is fine for a chart — just never write the result back.

Currencies without two decimal places

Japanese yen has none. Kuwaiti dinar has three. If you are even slightly likely to go multi-currency, store the exponent next to the amount rather than assuming 100. Retrofitting that is a migration nobody wants to run.

It takes an extra hour on day one. The alternative is a reconciliation meeting where nobody can explain a four-taka discrepancy.

  • #backend
  • #databases
  • #money
  • #javascript
Share

Keep reading

Related articles

Lighthouse report with category scores, Core Web Vitals and a request waterfall

Performance · Oct 9, 2026 · 8 min read

A performance budget that survives the deadline

Every team agrees the site should be fast, right up until the marketing tag goes in on a Thursday. Here is the setup that makes the budget hold without anyone having to be the villain.

#performance#core web vitals#next.js
Code editor with a file tree, an open component file and a terminal below

Next.js · Sep 24, 2026 · 11 min read

Server components changed how I structure a Next.js app

After six App Router projects, the folder structure I keep arriving at — and the three mistakes I made in the first two that cost me the most time.

#next.js#react#server components
Storefront product listing with a promotional banner and product grid

UX Engineering · Sep 7, 2026 · 6 min read

Your loading spinner is probably making things worse

Skeletons and spinners feel like good UX. Measured against perceived performance, most of the ones I have shipped made the page feel slower. What to use instead.

#ux#performance#react