如何从ISOCurrencyCodes获取NSNumberFormatter货币样式? [英] How to get NSNumberFormatter currency style from ISOCurrencyCodes?
问题描述
如果我要使用欧元或美元(两种ISO货币代码),我怎样才能让我的NSNumberFormatter正确格式化我这样的字符串?
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代码:10.000,00€
美元代码:$ 10,000.00
For EUR code: 10.000,00 € For USD code: $10,000.00
我可以通过设置localeIdentifier来完成此操作。但我真的需要从ISO货币代码中获取它。这可能吗?
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]];
谢谢!
推荐答案
使用
NSNumberFormatter
的 setCurrencyCode:
方法。
[numberFormatter setCurrencyCode:@"EUR"];
或
[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.
这篇关于如何从ISOCurrencyCodes获取NSNumberFormatter货币样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!