-1

I am trying to format an integer to a currency with this code:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *str = [formatter stringFromNumber:num];

Everything works fine but the currency is coming from the locale of the iOS. Is there any way to change it using "EUR" or "USD" as currency?

PS. I tried also currencySymbol and currencyCode which change the string but not the formatting!

Update: I am asking if there is any way to format it with EUR USD and not de-DE or en-US

luk2302
  • 55,258
  • 23
  • 97
  • 137
user622203
  • 149
  • 6
  • 20
  • So change `de-DE` to `EUR` then in Adams example – JSA986 Oct 04 '15 at 09:31
  • ` formatter.locale = [NSLocale localeWithLocaleIdentifier:@"EUR"];` won't work! – user622203 Oct 04 '15 at 09:33
  • The point is format it to whatever currency you want! people are giving their time to help you for free so drop the attitude. If you search SO there are many answers on this – JSA986 Oct 04 '15 at 09:34
  • I apologize if my answers made you think that I demand the answers from other users instead for asking for help. Maybe is because my English are not good but nobody seems to understand my question. I am closing the question – user622203 Oct 04 '15 at 09:40
  • Ok no problem close and restate it then if you need to – JSA986 Oct 04 '15 at 09:42

1 Answers1

1

All you have to do is to set the locale to your formatter. For example:

formatter.locale = [NSLocale localeWithLocaleIdentifier:@"de-DE"];
Adam
  • 26,549
  • 8
  • 62
  • 79
  • I am asking if there is any way to format it with EUR USD and not de-DE or en-US – user622203 Oct 04 '15 at 09:12
  • 1
    You said that you have tried `currencyCode`. If you don't want to change the whole locale, changing only the code should be enough, or am I missing something from your question? – Adam Oct 04 '15 at 09:17
  • I want to change local using EUR or USD. Is there any way or I should maintain a plist with USD mapped to en_US and so on? – user622203 Oct 04 '15 at 09:29