Skip to content

fix: use ceiling division in calculate_factoring_fee to prevent truncation to zero#525

Merged
sanmipaul merged 1 commit into
astera-hq:mainfrom
Junman140:fix/factoring-fee-ceiling-division
May 28, 2026
Merged

fix: use ceiling division in calculate_factoring_fee to prevent truncation to zero#525
sanmipaul merged 1 commit into
astera-hq:mainfrom
Junman140:fix/factoring-fee-ceiling-division

Conversation

@Junman140
Copy link
Copy Markdown
Contributor

@Junman140 Junman140 commented May 28, 2026

Closes #355


Integer division truncates toward zero, so when principal × fee_bps < BPS_DENOM
(10_000), the fee silently rounds to 0 regardless of the configured rate.
This affects small invoices: e.g. 50 stroops at 1% (100 bps) → fee = 0.

Replace truncating division with ceiling division:
fee = (numerator + BPS_DENOM - 1) / BPS_DENOM

This guarantees any non-zero fee rate on any non-zero principal yields
at least 1 stroop. No behaviour change for normal-sized invoices
(the +9999 is washed out by integer division).

…ation to zero

Integer division truncates toward zero, so when principal × fee_bps < BPS_DENOM
(10_000), the fee silently rounds to 0 regardless of the configured rate.
This affects small invoices: e.g. 50 stroops at 1% (100 bps) → fee = 0.

Replace truncating division with ceiling division:
  fee = (numerator + BPS_DENOM - 1) / BPS_DENOM

This guarantees any non-zero fee rate on any non-zero principal yields
at least 1 stroop. No behaviour change for normal-sized invoices
(the +9999 is washed out by integer division).
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@Junman140 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! 🚀

Learn more about application limits

@sanmipaul sanmipaul merged commit c2f1a04 into astera-hq:main May 28, 2026
10 of 15 checks passed
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.

fix: pool calculate_factoring_fee truncates fractional cents on small invoices

2 participants