iPhone:如何获取本地货币符号(即"$"而不是"AU $") [英] iPhone: How to get local currency symbol (i.e. "$" instead of "AU$")

查看:152
本文介绍了iPhone:如何获取本地货币符号(即"$"而不是"AU $")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我现在如何获取货币符号的代码:

Here's a code of how I get currency symbol now:

NSLocale *lcl = [[[NSLocale alloc] initWithLocaleIdentifier:@"au_AU"] autorelease];
NSNumberFormatter *fmtr = [[[NSNumberFormatter alloc] init] autorelease];
[fmtr setNumberStyle:NSNumberFormatterCurrencyStyle];
[fmtr setLocale:lcl];

NSLog( @"%@", [lcl displayNameForKey:NSLocaleCurrencySymbol value:@"AUD"] );
NSLog( @"%@", [fmtr currencySymbol] );

两个NSLogs均返回"AU $".正如我从Apple开发文档中了解到的那样,每种货币至少有两个货币符号(尽管这些符号可能是相同的)-本地(在一个国家内使用,例如,澳大利亚为$)和国际(澳元)对于澳大利亚).因此,问题是如何获取本地货币符号.有什么想法吗?

Both NSLogs return "AU$". As I understood from Apple development documentation, there are at least two currency symbols for each currency (these symbols could be the same, though) - local (that is used within a country. $ for Australia, for example) and international (AU$ for Australia). So, the question is how to get LOCAL currency symbol. Any ideas?

谢谢.

推荐答案

您的代码应该可以工作,但是语言环境标识符错误.它应该是"en_AU".

Your code should work, however the locale identifier is wrong. It should be "en_AU".

请参阅《国际化和本地化指南》中的使用语言环境对象"(

See "Using the Locale Object" in the "Internationalization and Localization Guide" (https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/InternationalizingLocaleData/InternationalizingLocaleData.html#//apple_ref/doc/uid/10000171i-CH13-SW4)

这篇关于iPhone:如何获取本地货币符号(即"$"而不是"AU $")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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