purchases-flutter
purchases-flutter copied to clipboard
The price returned is incorrect
I created a subscription product and set the price to $39.99. But in the requested data, the price is 39.989999999999995, not 39.99. I need to divide the price by 12 to calculate the price for each month.
StoreProduct(identifier: xxxx, description: xxxxx, title: xxxx, price: 39.989999999999995, priceString: $39.99, currencyCode: USD, introductoryPrice: IntroductoryPrice(price: 0.0, priceString: $0.00, period: P1W, cycles: 1, periodUnit: PeriodUnit.week, periodNumberOfUnits: 1), discounts: [], productCategory: ProductCategory.subscription, defaultOption: null, subscriptionOptions: null, presentedOfferingIdentifier: null, subscriptionPeriod: P1Y)
👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!
Can you please confirm the platform where you're seeing this, the version of the SDK you're using, and the system where you're seeing this, that way we can see where the floating point number is losing precision.
Thank you!
It's not really losing precision. See https://github.com/RevenueCat/purchases-ios/issues/2207#issuecomment-1419737170
That's just an imperfect decimal representation of IEEE 754 floats.
Instead, make sure you use the display
methods to properly convert these prices to String
s.
I'm seeing this too.
2.9899999999999998, 24.990000000000002,
https://en.wikipedia.org/wiki/IEEE_754