Skip to content

fix: roundToCents uses Math.round instead of Math.floor to round to n… - #1453

Open
jotel-dev wants to merge 1 commit into
LabsCrypt:mainfrom
jotel-dev:1372-backend-fix-rounding-down
Open

fix: roundToCents uses Math.round instead of Math.floor to round to n…#1453
jotel-dev wants to merge 1 commit into
LabsCrypt:mainfrom
jotel-dev:1372-backend-fix-rounding-down

Conversation

@jotel-dev

Copy link
Copy Markdown

The fix is complete. Here's a summary:

Fix: Changed Math.floor to Math.round in roundToCents at backend/src/controllers/loanController.ts:228, so values round to the nearest cent instead of always rounding down.

Branch: 1372-backend-fix-rounding-down
Commit: f3a9636 — fix: roundToCents uses Math.round instead of Math.floor to round to nearest cent

closes #1372

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right diagnosis, Math.floor always rounding down is a real bug. but the repo money policy (backend/src/money/policy.generated.ts) specifies half_even rounding, and Math.round is half-up (and asymmetric for negatives), so this fix trades one policy violation for another. the money-policy CI job only checks artifact drift, which is why it stays green.

  1. round via the half-even helper in backend/src/money/decimal.ts (or equivalent) instead of Math.round.
  2. add a unit test covering the .5 cases (e.g. 0.125 -> 0.12 and 0.135 -> 0.14).

if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

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.

[Backend] Owed values are always rounded down

2 participants