gpt4 book ai didi

iphone - 在 iPhone SDK 中使用货币代码显示货币符号

转载 作者:行者123 更新时间:2023-12-03 17:29:13 25 4
gpt4 key购买 nike

实际上,我想显示所有货币代码的货币符号,并且我使用这样的代码,但我只得到“$”符号

-(void) showCurrenciesList
{
NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
[numFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
//[numFormatter setLocale: [NSLocale currentLocale]];

NSMutableArray *aryAllCurrencies = [[NSMutableArray alloc] init];
//NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier: @"en_US"] autorelease];

NSArray *currencyArray = [NSLocale ISOCurrencyCodes];
NSLog(@"Currency array : %@",currencyArray);

for (NSString *currencyCode in currencyArray)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[numFormatter setCurrencyCode:currencyCode];
NSString *currencySymbol = [numFormatter currencySymbol];
[aryAllCurrencies addObject:currencySymbol];
[pool release];
}
//[countriesArray sortUsingSelector:@selector(compare:)];
NSLog(@"currencies array : %@",aryAllCurrencies);
}

这是正确的还是有其他方法可以做到这一点?

最佳答案

这是一个直接的高成本解决方案

+(NSString *)getCurrencySybolByCurrecyCode:(NSString *)code
{
NSArray *locales = [NSLocale availableLocaleIdentifiers];
for (NSString *currentLocale in locales)
{
NSLocale *currentLoc = [[[NSLocale alloc] initWithLocaleIdentifier:currentLocale] autorelease];
if([[currentLoc objectForKey:NSLocaleCurrencyCode] isEqualToString:code])
{
NSLog(@"find symbol for code = %@ %@", [currentLoc objectForKey:NSLocaleCurrencyCode], [currentLoc objectForKey:NSLocaleCurrencySymbol]);
return [currentLoc objectForKey:NSLocaleCurrencySymbol]; }
}
return nil;
}

关于iphone - 在 iPhone SDK 中使用货币代码显示货币符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6279124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com