Alfie gf - #461
Merged
Merged
Conversation
added 6 commits
August 16, 2026 03:12
Introduces a BigInt-based Money class that stores values scaled to 7 decimal places, eliminating JS floating-point drift in payroll calculations. Supports arithmetic, percentage, and comparison operations without intermediate rounding loss.
18 tests covering construction, arithmetic, percentage, comparison, and a regression test that verifies 10 stacked percentage deductions sum exactly to the expected total with no floating-point drift.
Replaces parseFloat/toFixed(7) arithmetic in calculateDeductionsRuleBased and generateReport with Money operations. Eliminates floating-point drift in stacked tax rule sums. All 18 existing taxService tests pass.
Replaces round7/parseFloat arithmetic in generateDraftPayslip with Money.percentage and Money.from for deduction rule and tax rule calculations, and uses Money for accumulating total deductions.
Replaces .reduce with parseFloat/.toFixed(7) accumulation in getPayrollRunSummary with Money-based summing for base, bonus, and total amounts.
Tests verify that Money preserves gross === total + net exactly across 10 and 20 stacked percentage deductions with fractional rates, and that the old parseFloat/toFixed pattern produces the correct result for the specific test case while Money guarantees it for all inputs.
3 tasks
Contributor
|
Thank you @alfeedrips for your contribution |
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.
Summary
Introduces a shared Money fixed-point type for payroll financial math, eliminating JS floating-point drift across tax, benefits, and bonus calculations. Replaces the repeated parseFloat((...).toFixed(7)) + float += anti-pattern with BigInt-based arithmetic that guarantees exact results.
Changes
Testing
npx jest src/services/tests/taxService.test.ts src/utils/tests/money.test.ts --no-coverage
Tradeoffs
Architecture
backend/src/utils/money.ts ← shared Money type (BigInt, 7 decimals)
backend/src/services/taxService.ts ← uses Money for deduction rules
backend/src/services/benefitsService.ts ← uses Money for payslip generation
backend/src/services/payrollBonusService.ts ← uses Money for summary totals
Out of scope
Closes Financial calculations use floating-point math instead of fixed-point/decimal — cumulative rounding drift #451