Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get NSNumberFormatter currency style from ISOCurrencyCodes?

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!

like image 977
nmdias Avatar asked Nov 04 '13 17:11

nmdias


1 Answers

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.

like image 109
rmaddy Avatar answered Sep 19 '22 17:09

rmaddy