Skip to content
JournalTORIS / FIELD NOTES

← Blog Project notes

Who Gets the Leftover 1 Won in a 1/N Split?

Looking back at LOVETRIP's budget and settlement feature: preserving totals, distribution rules, and consistency at save time, with an illustrative integer-split example.

2 min read Read the Korean original

Joohwan Yu · Founder, Full Stack Developer

Toris · Published

Contents

While implementing budgets and 1/N settlement in LOVETRIP, I felt that money calculations should be handled more conservatively than other UI calculations. If a place recommendation is a bit off, you can pick a different course. But if the total and each person’s share don’t add up, you end up re-checking the whole product.

The rules remain after the division

When several people split an integer won amount, a remainder can appear. If you try to solve it by hiding the decimal places, the sum of the individual amounts differs from the original total. The problem is not just JavaScript syntax. You need a product rule for who gets the leftover amount.

The code below is not the production source from the time, but an example illustrating one way of preserving the total. It restricts the input to a non-negative safe integer amount and a headcount of 1 to 1,000.

function splitWon(total: number, count: number): number[] {
  if (!Number.isSafeInteger(total) || total < 0 ||
      !Number.isInteger(count) || count < 1 || count > 1000) {
    throw new Error('금액과 인원수를 확인하세요.');
  }
  const base = Math.floor(total / count);
  const remainder = total % count;
  return Array.from({ length: count }, (_, i) =>
    base + (i < remainder ? 1 : 0));
}
// splitWon(10000, 3) → [3334, 3333, 3333]

Even when exact, you have to explain the fairness

This example assigns the remainder to the people at the front. So if the order of people changes, the amounts they owe change too. In a real product, a separate choice is needed, such as fixing the order stably or letting users adjust it. A total that is mathematically right and a result users find acceptable are different standards.

If I were verifying it again now, I would look first at a total of 0, a total smaller than the headcount, and amounts that don’t divide evenly. Whether the individual shares sum to the original amount, and whether the gap between the maximum and minimum doesn’t exceed 1 won, are the key conditions of this simple even-split example.

Calculation and storage had to be checked separately

Even if the screen calculates correctly, the settlement state goes wrong if only some items change during saving. When redesigning, I would review the boundary between editing items and reflecting the total together. I won’t claim this example solves refunds, multiple currencies, or partial participation. If such requirements arise, you have to settle the unit of the amount and the distribution policy first.

LOVETRIP showed me that a small difference in amount can become a large difference in trust. Next time, rather than writing the formula first, I’ll write down the conditions that preserve the total and the rule for handling the remainder.

Related post: LOVETRIP budget management experience

Advertisement