Repository navigation
Fix #178: Splitting $10.00 three ways loses a cent - #192
Closed
Param-Harrison wants to merge 2 commits into
Closed
Param-Harrison wants to merge 2 commits into
Param-Harrison wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Closing as stale: superseded by the current factory runs; the issue stays open to be re-run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
splitCentsrounded 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:splitCentsnow follows the remainder rule in.claude/skills/handling-money/references/rules.md. It computesbase = floor(total / n)andremainder = total - base * n, and the firstremaindermembers, in the order passed in, getbase + 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:
createExpenseinsrc/expenses.tsstores whateversplitCentsreturns.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 testpasses: 43 tests, 0 failures. I did not run the issue'scheck-cents.tsscript because the session's permission mode blocked the command.Review
The
code-reviewersubagent approved the change. It worked through the cases by hand and did not run the tests. Its notes:tests/routes.test.ts.splitCentsdoesn'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