Skip to content

Fix price-per-period rounding to floor instead of round-half-up#807

Merged
dpannasch merged 2 commits into
mainfrom
fix/round-down-price-per-period
Mar 19, 2026
Merged

Fix price-per-period rounding to floor instead of round-half-up#807
dpannasch merged 2 commits into
mainfrom
fix/round-down-price-per-period

Conversation

@dpannasch

Copy link
Copy Markdown
Contributor

Summary

  • Per-period price calculations (pricePerWeek, pricePerMonth, pricePerYear) were using Math.round / Intl.NumberFormat halfExpand rounding, causing prices like $83.99/yr to display as $7.00/mo instead of $6.99/mo
  • Added shared floorMicrosToCurrencyUnit helper with cached Intl.NumberFormat lookup and IEEE 754 epsilon correction
  • Fixed both code paths: offerings.ts (toPricingPhase entity builder) and paywall-price-helpers.ts (paywall variable formatting)
  • Matches iOS SDK behavior from purchases-ios#5821

Test plan

  • Updated existing per-period price tests across 3 test files (538 total tests pass)
  • Added unit tests for floorMicrosToCurrencyUnit covering USD, EUR, JPY, zero values, and FP epsilon
  • TypeScript typecheck and ESLint pass
  • Manual verification with paywall displaying annual/6-month packages

🤖 Generated with Claude Code

Per-period prices (pricePerWeek, pricePerMonth, pricePerYear) were rounding
up via Math.round / Intl.NumberFormat halfExpand, causing prices like
$83.99/yr to show $7.00/mo instead of $6.99/mo. This aligns with the
iOS SDK fix (purchases-ios#5821) to always round down, ensuring per-period
prices never exceed what the customer actually pays.

Changes:
- Add shared floorMicrosToCurrencyUnit helper in price-labels.ts with
  cached Intl.NumberFormat lookup and IEEE 754 epsilon correction
- Fix offerings.ts toPricingPhase to floor per-period micros to the
  currency's display precision
- Fix paywall-price-helpers.ts to floor divided micros before formatting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dpannasch dpannasch merged commit eab77a0 into main Mar 19, 2026
6 checks passed
@dpannasch dpannasch deleted the fix/round-down-price-per-period branch March 19, 2026 13:06
tonidero pushed a commit that referenced this pull request Mar 24, 2026
**This is an automatic release.**

## RevenueCat SDK
### ✨ New Features
* Refactor wallet button renderer (#810) via Marek Dabek (@marek-dabek)
### 🐞 Bugfixes
* Add font-family to simulated store modal (#809) via Perttu
(@plahteenlahti)
* Fix price-per-period rounding to floor instead of round-half-up (#807)
via Dan Pannasch (@dpannasch)

### 🔄 Other Changes
* Require PR approval before release tagging (#811) via Antonio Pallares
(@ajpallares)
* PW-1121 | Add paywall events (impression, close, cancel) (#806) via
Drago Crnjac (@popcorn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants