Solved

Prices off by 1 cent (ish)

  • 21 September 2021
  • 3 replies
  • 82 views

Badge +3
  • Dedicated Member
  • 22 replies

When I use the price string from the API, we see 12.99 like we have in the Apple app store. However, when I access the price itself in the Flutter client library, I see 12.989999771118164. I am not manipulating this price at all, I am printing it directly from Flutter lib. Do you think this is: 1) Apple weirdness 2) RevenueCat API bug OR 3) Flutter bug?

icon

Best answer by ryan 21 September 2021, 19:39

View original

3 replies

Userlevel 5
Badge +9

This is due to the nature of floating point decimals. More info in this Stackoverflow post here: https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate

Rounding the float to 2 decimals should land you with the correct formatted currency. There may be some enhancement we could do in the SDK to improve how these are displayed. @taquitos knows more about floating point accuracy than me...

Badge +3

Rounding something like 5.999 even to 2 decimals takes you to “6” so it won’t always work. Maybe in this case though

Userlevel 5
Badge +9

Rounding something like 5.999 even to 2 decimals takes you to “6” so it won’t always work. Maybe in this case though

I don’t think you would run into that, since $5.99, converted to a float should still round back to $5.99. If it was $6.00 then you could see a case of 5.9999 or 6.0001.

Reply