• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to retrieve currencies list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: How to cancel a view-initiated update (model vs view out of sync)
  • Next by Date: Re: KVO/dealloc problems
  • Previous by thread: Re: How to retrieve currencies list
  • Next by thread: Selector of Open recent document
  • Index(es):
    • Date
    • Thread