Three roommates, $1,800 rent, three bedrooms of very different sizes. "Split it by room size" sounds like one line of code. It's three lines, plus one cent that keeps going missing.
This post walks through three ways to split rent and utilities, the numbers for each, and a small JavaScript function that always adds up to the exact total.
The example
- Rent: $1,800 a month
- Utilities: $240 a month
- Ana: 200 sq ft (with its own bathroom)
- Ben: 150 sq ft
- Cleo: 125 sq ft
Three methods, side by side
| Method | How rent is split | Ana | Ben | Cleo | Best when |
|---|---|---|---|---|---|
| Equal | 1/3 each | $680.00 | $680.00 | $680.00 | Rooms are similar |
| By room size | Weighted by sq ft | $837.90 | $648.42 | $553.68 | Little shared space |
| Hybrid | 50% equal, 50% by sq ft | $758.95 | $664.21 | $616.84 | Shared kitchen and lounge |
All three include utilities split equally ($80 each). Every row adds up to exactly $2,040.00.
The bug: weighted shares don't add up
The naive version:
const weights = [200, 150, 125]; const total = 1800; const sum = weights.reduce((a, b) => a + b, 0); const shares = weights.map(w => Math.round((total * w / sum) * 100) / 100); // [757.89, 568.42, 473.68] -> 1799.99 One cent short. Not a big deal on paper, but it means the transfers never match the landlord's number, and someone ends up "owing" a cent nobody can explain. Floats make it worse on bigger lists.
The fix: integer cents + largest remainder
- Work in integer cents.
- Floor every share.
- Hand the leftover cents, one each, to the shares with the biggest fractional parts.
function splitByWeight(totalCents, weights) { const sum = weights.reduce((a, b) => a + b, 0); const raw = weights.map(w => (totalCents * w) / sum); const shares = raw.map(Math.floor); let left = totalCents - shares.reduce((a, b) => a + b, 0); // biggest fractional part first; ties go to the earlier person const order = raw .map((r, i) => ({ i, frac: r - Math.floor(r) })) .sort((a, b) => b.frac - a.frac || a.i - b.i); for (const { i } of order) { if (left === 0) break; shares[i] += 1; left -= 1; } return shares; } splitByWeight(180000, [200, 150, 125]); // [75790, 56842, 47368] -> $1,800.00 The hybrid is just two calls added together:
const equalHalf = splitByWeight(90000, [1, 1, 1]); // [30000, 30000, 30000] const sizeHalf = splitByWeight(90000, [200, 150, 125]); // [37895, 28421, 23684] const utilities = splitByWeight(24000, [1, 1, 1]); // [8000, 8000, 8000] // Ana 75895, Ben 66421, Cleo 61684 -> $758.95 / $664.21 / $616.84 The tie-break matters: deterministic means the same inputs always give the same person the extra cent, so nobody's share changes when the app re-renders.
Utilities: equal by default, weighted when it's obvious
If one roommate works from home all day, a 2:1:1 weighting is easy to justify: splitByWeight(24000, [2, 1, 1]) gives [12000, 6000, 6000], so $120 / $60 / $60. Same function, different weights.
Checklist for anyone building this
- Store and compute money as integer cents (or a decimal type), never floats.
- Assert
sum(shares) === totalafter every split. It's a one-line test that catches most bugs. - Make the remainder rule deterministic and explainable.
- Show people the method, not just the numbers. "By room size, 42.1%" is easier to accept than "$837.90".
If you want to try these splits without writing code, our Smart Bill Splitter does equal, weighted and itemized splits in the browser and handles the leftover cent the same way.
TechnBean designs and builds web and mobile apps, UX and agentic AI products. If you're building something around shared money or fintech, we'd love to compare notes.



