Skip to content

Fix #178: Splitting $10.00 three ways loses a cent - #192

Closed
Param-Harrison wants to merge 2 commits into
mainfrom
worktree-issue-178
Closed

Param-Harrison wants to merge 2 commits into
mainfrom
worktree-issue-178

Conversation

@Param-Harrison

Copy link
Copy Markdown
Contributor

What was wrong

splitCents rounded every share down and threw away the remainder. Splitting 1000 cents among 3 members gave 333/333/333, which adds up to 999, so one cent was lost.

The fix

  • src/money/cents.ts: splitCents now follows the remainder rule in .claude/skills/handling-money/references/rules.md. It computes base = floor(total / n) and remainder = total - base * n, and the first remainder members, in the order passed in, get base + 1. The shares now always add up to the total. Negative totals work too: -1000 split 3 ways gives -333, -333, -334. I replaced the old "SEEDED DEFECT" doc comment with a description of the rule.
  • tests/routes.test.ts: I removed a comment that described the remainder bug as still open. The reviewer flagged it.

No caller needed changing: createExpense in src/expenses.ts stores whatever splitCents returns.

The test

I added two tests to tests/money.test.ts:

  • gives the leftover cent to the first member (issue #178): splitCents(1000, ["a","b","c"]) returns {a:334, b:333, c:333}, which adds up to 1000.
  • gives leftover cents to the first N members in order: splitCents(1001, ["a","b","c"]) returns {a:334, b:334, c:333}, which adds up to 1001.

Both failed before the fix, because they got 333/333/333. After it, bun test passes: 43 tests, 0 failures. I did not run the issue's check-cents.ts script because the session's permission mode blocked the command.

Review

The code-reviewer subagent approved the change. It worked through the cases by hand and did not run the tests. Its notes:

  • Fixed in this PR: the outdated comment in tests/routes.test.ts.
  • Not fixed here (they predate this change): splitCents doesn't check its input. If a member id appears twice, both shares land on one key and cents are lost. A total with a fraction of a cent, such as 10.5, gives shares that don't add up to it. Each is worth its own issue.

🤖 Generated with Claude Code

Fixes #178

Param-Harrison and others added 2 commits October 14, 2026 12:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Param-Harrison

Copy link
Copy Markdown
Contributor Author

Closing as stale: superseded by the current factory runs; the issue stays open to be re-run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Splitting $10.00 three ways loses a cent

1 participant