5

If I were to have EUR, or USD (both ISO currency codes), how could I make my NSNumberFormatter to properly format me a string like this?

For EUR code: 10.000,00 € For USD code: $10,000.00

I could do this by setting localeIdentifier. But I really need to get it from the ISO currency code. Is this possible?

[numberFormatter stringFromNumber: [_property price]];

Thank you!

nmdias
  • 3,888
  • 5
  • 36
  • 59

1 Answers1

10

Use the setCurrencyCode: method of NSNumberFormatter.

[numberFormatter setCurrencyCode:@"EUR"];

or

[numberFormatter setCurrencyCode:@"USD"];

Keep in mind that even though the desired currency symbol will be used, the resulting currency value string is still going to be formatted based on the user's locale.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    That's actually what I'm trying to do. To get a string that is NOT based on user's locale, but one that is properply formatted from a currency code. – nmdias Nov 04 '13 at 18:23
  • 5
    But that makes no sense. The Euro is used by people from many different locales, for example. Some want to see `1 000.00 €`, some want `1.000,00 €`, some want `€1,000.00`, etc. There is no single "proper" format for a given currency code. – rmaddy Nov 04 '13 at 18:30
  • 1
    Euro formatting does not change based on your location. It doesn't matter if you're in Spain, Portugal or France. This is to be integrated with a Web Service, and I need the display to be in a specific currency, regardless of a user's location. I could just give it a country with it's currency, but feels like a hammer solution. :( – nmdias Nov 05 '13 at 08:48
  • 11
    You have no choice. Even USD is used in multiple locales. Personally I disagree with your assessment. I live in the USA. I want to see USD as `$10,000.00`. I also want to see EUR as `€10,000.00`. I do not want to see it as `10.000,00 €`. That's confusing to people in the USA because we use the opposite grouping and decimal symbols. Good luck with whatever you decided. – rmaddy Nov 05 '13 at 17:15
  • Looking for a solution for this, specially because the country where I am from has specific laws about it (here the law is that BRL is always in the format R$10.000,00 never R$10,000.00 or any variation with spaces, different groupoings and whatnot) – speeder Feb 11 '16 at 17:49