In a bug report regarding the Discourse Subscriptions plugin, RGJ identified a floating-point precision error preventing users from setting subscription prices to $19.99. The issue stems from IEEE-754 arithmetic where parseFloat('19.99') * 100 results in 1998.9999999999998, causing the Stripe API to reject the value as an invalid integer. RGJ suggested fixing the JavaScript code in plan.js by using Math.round() to handle the conversion. pfaffman and sam discussed the root cause, noting that while storing values as cents (integers) is the standard approach (as Stripe does), the immediate fix of rounding the float conversion is less invasive. RGJ clarified that the unit_amount is passed to Stripe as cents, but the input field requires a decimal representation. Bruce5051 noted that Binary Coded Decimal (BCD) would be more suitable for currency, though not immediately applicable. The issue was acknowledged by zogstrip, who confirmed a fix was merged in pull request #37877.
Yes, that’s what it does, unit_amount are cents and the amountDollars is an ‘XX.XX’ input value.
The “invalid integer” error even comes from the Stripe API.
I guess we’re both old enough to know about the FDIV bug
It is, the parseFloat is used to convert from/to input field which is “currency with two decimals”. The unit_amount object property is obviously typeless though, hence my suggestion to use Math.round()
It is not a column server side, it is passed to the Stripe API.