zkwentz
zkwentz

Reputation: 1105

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:

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

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?

Upvotes: 1

Views: 855

Answers (2)

AliSoftware
AliSoftware

Reputation: 32681

Yes you should convert your (unformatted) strings to numbers and then use NSNumberFormatter to strings.

Upvotes: 2

Brandon J. Boone
Brandon J. Boone

Reputation: 16472

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

Upvotes: 3

Related Questions