Skip to content

Commit 7583fdb

Browse files
committed
chore: document float division
1 parent d81d19e commit 7583fdb

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

apps/backend/src/lib/payments/platform-fees.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ export function computeApplicationFeeAmount(options: { amountStripeUnits: number
3636
return Math.round(options.amountStripeUnits * bps / 10000);
3737
}
3838

39+
/**
40+
* Returns the fee as a decimal percent for Stripe's `application_fee_percent`
41+
* (subscription) parameter, or `undefined` for projects that aren't billed.
42+
*
43+
* `bps / 100` is intentional float division — the rest of the module uses
44+
* integer arithmetic to avoid IEEE-754 noise on charge-amount math, but the
45+
* subscription path requires a decimal because that's the shape Stripe's API
46+
* accepts. This is safe for the current 90 bps (→ 0.9, which serialises
47+
* cleanly), and any future bps value must produce a number with at most 4
48+
* decimal places after IEEE-754 rounding — that's the maximum precision
49+
* Stripe documents for `application_fee_percent`.
50+
*/
3951
export function getApplicationFeePercentOrUndefined(projectId: string): number | undefined {
4052
const bps = getApplicationFeeBps(projectId);
4153
if (bps === 0) return undefined;

0 commit comments

Comments
 (0)