If you want a dollar sign and just a dollar sign, why not just specify a format like '$#,##0.00'
with a literal $
? Alternatively, specify a locale that will format the amount the way you want by default.
Specifying NSNumberFormatterCurrencyStyle
is just a shortcut to setting whatever the locale's standard currency format is, which will include whether the symbol is prefixed or suffixed to the amount, but has little bearing on what you're doing, as you are specifying the format by hand.
You're seeing US$
because it is formatting the currency USD appropriately for your region. (Though you must have mixed up your format string and your output, because it does respect whether you request prefix or suffix placement of the currency code.) But darvids0n is mostly right:
- One currency symbol in the format string places the locale's symbol for that currency, which is "$" in en and
US$
in many others;
- Two places the international symbol, like "USD";
- Three places the locale's display name for that currency, like "US dollar".
Here is an example of this behavior using the Swedish locale (inherited by default, not set explicitly; that's what my machine is set in right now):
> nf := NSNumberFormatter alloc init
> nf setNumberStyle:NSNumberFormatterDecimalStyle
> amt := 1250.56
> nf setPositiveFormat:'¤ #,##0.00'
> nf stringFromNumber:amt
'US$ 1 250,56'
> nf setPositiveFormat:'#,##0.00 ¤'
> nf stringFromNumber:amt
'1 250,56 US$'
> nf setPositiveFormat:'#,##0.00 ¤¤'
> nf stringFromNumber:amt
'1 250,56 USD'
> nf setPositiveFormat:'#,##0.00 ¤¤¤'
> nf stringFromNumber:amt
'1 250,56 US-dollar'
(The syntax is that of F-Script.)