A paywall is a strange screen: tiny, high-stakes, and almost entirely made of edge cases. I spent the last week building six of them on one controller β a trial timeline, a feature matrix, tier cards, a single-product hero, a cancel-flow offer and a three-step onboarding funnel β with no third-party packages. Two of the bugs below were designed out before they could ship; the other two bit me anyway.
Here is what broke and what the fix looks like.
1. Money as a double drifts, so never let it hold a price
The obvious implementation is double price = 29.99 and price / 12 for the monthly equivalent. It prints 2.4991666... and then every formatter rounds it its own way: one screen shows $2.49 , another shows $2.50 , and the receipt disagrees with both.
The kit stores integer minor units instead, with the currency's own decimal digits β 2 for USD, 0 for JPY:
const Money yearly = Money ( 2999 ) ; // $29.99 yearly . dividedBy ( 12 ) .β¦