feat(tax_deduction_estimator): configure decimal rounding policies (#… - #590
Merged
2 commits merged intoSep 28, 2026
Merged
2 commits merged into
2 commits merged into
Conversation
|
@EDOHWARES Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
godamongstmen897
pushed a commit
that referenced
this pull request
Sep 28, 2026
godamongstmen897
pushed a commit
that referenced
this pull request
Sep 28, 2026
#590 made half-even the default rounding policy for calculateTaxDeduction and estimateBracketTax, which would silently change the tax amount existing callers (routes, formatForDbStorage, CSV export, bracket estimates) compute on halves and above-half fractions. Keep "truncate" (plain bigint division, the pre-#590 behaviour) as the default for both functions and roundIntegerDivision; the new policies stay available as an explicit opt-in. Also fix roundIntegerDivision's "truncate" for negative numerators, which rounded toward negative infinity like "floor"; it now rounds toward zero, and "floor" keeps rounding down. Update #590's tests: the default-policy test now asserts truncation, the half-even cases pass the policy explicitly, and a new case covers the default and truncate vs floor on negatives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJM5SuF3hAuKGMpPBz7Rwr
de734c9
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.
Description
Resolves #449
This PR configures consistent decimal rounding policies and remainder validation within
tax_deduction_estimator. It introduces configurable rounding protocols (defaulting to Banker's rounding / round-to-nearest-even) for division operations and ensures intermediate division remainders are accurately preserved and validated.Key Changes
src/utils/tax_deduction_estimator.ts):RoundingPolicysupporting"half-even"/"round-to-nearest-even"(default),"half-up","truncate","ceil", and"floor".roundIntegerDivision(numerator, divisor, mode)helper for integer-based rounding arithmetic.calculateTaxDeductionandestimateBracketTaxto accept rounding policies via parameter or options object ({ roundingMode }).ERROR_CODES.INVALID_ROUNDING_MODE(TAX_ESTIMATOR_INVALID_ROUNDING_MODE) for invalid policy rejection.roundingModeintoDbPrecisionSchema(for DB formatting) andTaxCsvExportOptions(for CSV exports).verifyTaxDeductionRemainder(and aliasvalidateTaxDeductionRemainder) to assert that intermediate division remainders are not dropped or lost (grossAmount * taxRate === unroundedTax * taxScale + remainder) and total funds are conserved (grossAmount === netAmount + taxAmount).__tests__/tax_deduction_estimator.test.ts):roundIntegerDivisionacross all rounding policies.Verification & Testing
npx tsc --noEmitwith 0 errors.npm run build.__tests__/tax_deduction_estimator.test.tsand 100 tests in__tests__/tax_bracket_estimator.test.ts.Closes #449
Closes #448
Closes #447
Closes #446