0


In my application it's possible to store a price for every object and the user can also choose its preferred currency.
What is the best way to store and manage number with currency in iPhone SDK?

More infos about my app:
It uses Core Data.
Number that can be stored must be of type xxx.xx (e.g. 100.00).
How can I sort these numbers ascending or descending?
What kind of attribute I must set in my entity to store a number like this?

Have you got links, docs, source or guides to show me examples? I never user number with currency, then I've got some problems with them :)

Thanks a lot,
Matthew

matteodv
  • 3,992
  • 5
  • 39
  • 73

1 Answers1

2

Store it in GP (gold pieces) with a conversion factor ;)

It doesn't look like there's a datatype for currency, so storing the number and decimal part, and a setting for the current currency, is probably as good as you're going to get. See this: HowTo for newbie: Managing currency in iPhone app

Community
  • 1
  • 1
Robert
  • 6,412
  • 3
  • 24
  • 26
  • 1
    Just to be clear, I was joking about the gold pieces thing... as far as just storing it as a number with a bit of data somewhere that says whether you're currently using dollars, euro, yen, etc should work. But it doesn't seem like Apple has created a datatype for this. – Robert Dec 07 '10 at 00:42
  • In my entity, what kind of attribute must I use? Float, double... Thanks! – matteodv Dec 07 '10 at 05:22
  • 1
    Decimal because float and double can remove precision. The only annoying thing with NSDecimalNumber is the operators are messages instead of +-/* – Brent Priddy Dec 07 '10 at 15:19
  • For now, I believe I will not use operations with these number but if I'll use them, what do you mean with the phrase "the operators are messages instead of +-/*"? Is there some info about this on the Apple Developer Site? Thanks :) – matteodv Dec 07 '10 at 16:16