如何从ISOCurrencyCodes获取NSNumberFormatter货币样式? [英] How to get NSNumberFormatter currency style from ISOCurrencyCodes?

查看:133
本文介绍了如何从ISOCurrencyCodes获取NSNumberFormatter货币样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我要使用欧元或美元(两种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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆