Search code examples
iphoneobjective-cnsstringnsnumber

Formatting an NSString as a currency, should I use NSNumberFormatter?


I have a series of strings that come in, that are essentially dollar values, but they are unformatted.

So for example they look like this:

  • -5
  • -2.5
  • 697.5
  • 0

I want to format these as a currency, like this:

  • ($5.00)
  • ($2.50)
  • $697.50
  • $0.00

Ideally, I'd like it to be localized as well. I know I can use NSNumberFormatter to achieve this, but that would involve me converting these strings to NSNumbers and the formatting them with my formatter, only to convert them back to strings from the NSNumber that has been formatted.

Is there a way to skip the number conversion altogether and just format the string?


Solution

  • From the documentation here it doesn't look like it.

    EDIT

    Similar Question was also asked:

    Easiest way to convert a NSString to its currency equivalent in Cocoa