iPhone:如何获得本地货币符号(即“$”不符合“AU $”) [英] iPhone: How to get local currency symbol (i.e. "$" unstead of "AU$")

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

问题描述



  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]);

两个NSLog都返回AU $。根据我对苹果开发文档的理解,每种货币至少有两个货币符号(尽管这些符号可能相同) - 本地(在一个国家内使用,例如澳大利亚使用$)和国际(澳元为澳大利亚)。所以,问题是如何获得本地货币符号。任何想法?

预先感谢。

解决方案

工作,但是区域标识符是错误的。它应该是en_AU。

请参阅国际化和本地化指南( https://developer.apple。 com / library / ios / documentation / MacOSX / Conceptual / BPInternational / InternationalizingLocaleData / InternationalizingLocaleData.html#// apple_ref / doc / uid / 10000171i-CH13-SW4

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] );

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?

Thanks in advance.

解决方案

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天全站免登陆