12
sambhal
6y

The iOS team lead stored the price in string format.

Comments
  • 2
    It MUST be stored in string format. Currency has to be handled as string. I'm sorry, but you're the wrong one here
  • 4
    The reason is easy, our calculators aren't good at handling decimals, and it can happen that 10.07 becomes 10.06. So you must handle them as string or, if you need to perform operations, multiply by 100 and handle them as int
  • 2
    @crisz or live in a country where there is no change, only integer currency values
  • 2
    @crisz what? Swift/Objective-C can't handle Decimals?
  • 3
    @C0D4 IEEE 754 (floatint point arithmetic specification) can't handle decimals with precision. Every programming language that implements it, will be affected with the same problem
  • 3
    @crisz but that's why we enforce 2 digit precision in other languages or do *100 scenario.

    Adds useless complexity but it works.
  • 1
    @oreru Not every implementation uses 52 bits. And by the way, precision decreases along with bigger integer parts
  • 0
    well it was not for precision or something else.
  • 0
    @crisz do you know the size of the integer you would need to not be accurate to 2 decimal points? More than your what your 32 bit Int arithmetic could handle. Store the damn thing as a Double and create an extension that returns a string when needed to display on UI. I guarantee OP’s lead did not have precision in mind when storing the property. He just wanted to make his job easier when displaying on the UI/too lazy to convert parsed JSON, assuming maybe the price comes in from API as a string. What was his justification OP?
  • 0
    Dude, I think TL only knew about string data type.
Add Comment