Re: How to retrieve currencies list
Re: How to retrieve currencies list
- Subject: Re: How to retrieve currencies list
- From: Thilo Ettelt <email@hidden>
- Date: Fri, 28 Apr 2006 11:37:24 +0200
Thank you for this long explanation. Just one more question: how do I
retrieve the currency symbols? I've tried that using the
NSNumberFormatter (setting locale to currentlocale and setting the
currency code), but that just returned nil for the currencySymbol. So
how can I get the symbol?
Thx in advance,
Thilo
This is what the "display name" method is for. In this case, you
ask the locale into which you want the name localized for the
display name of the particular currency code.
#import <Foundation/Foundation.h>
int main() {
NSLocale *locale;
NSString *dollars, *yen;
[NSAutoreleasePool new];
locale = [NSLocale currentLocale];
dollars = [locale displayNameForKey:NSLocaleCurrencyCode
value:@"USD"];
yen = [locale displayNameForKey:NSLocaleCurrencyCode
value:@"JPY"];
NSLog(@"%@: '%@', '%@'", [locale localeIdentifier], dollars, yen);
locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"de"]
autorelease];
dollars = [locale displayNameForKey:NSLocaleCurrencyCode
value:@"USD"];
yen = [locale displayNameForKey:NSLocaleCurrencyCode
value:@"JPY"];
NSLog(@"%@: '%@', '%@'", [locale localeIdentifier], dollars, yen);
locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr"]
autorelease];
dollars = [locale displayNameForKey:NSLocaleCurrencyCode
value:@"USD"];
yen = [locale displayNameForKey:NSLocaleCurrencyCode
value:@"JPY"];
NSLog(@"%@: '%@', '%@'", [locale localeIdentifier], dollars, yen);
return 0;
}
2006-04-27 16:24:52.511 a.out[3373] en_US: 'US Dollar', 'Japanese Yen'
2006-04-27 16:24:52.516 a.out[3373] de: 'US Dollar', 'Yen'
2006-04-27 16:24:52.516 a.out[3373] fr: 'dollar des États-Unis', 'yen'
Note that the system does not necessarily have localized names for
all combinations of languages and currencies.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden