• 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: Chris Kane <email@hidden>
  • Date: Fri, 28 Apr 2006 08:37:02 -0700

Try using the NSLocaleCurrencySymbol constant instead of the Code constant in the test program below. It doesn't make sense, I know, but the underlying ICU library is not always consistent.

Chris

On Apr 28, 2006, at 2:27 AM, Thilo Ettelt wrote:

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
References: 
 >How to retrieve currencies list (From: Eric Morand <email@hidden>)
 >Re: How to retrieve currencies list (From: Thilo Ettelt <email@hidden>)
 >Re: How to retrieve currencies list (From: Chris Kane <email@hidden>)

  • Prev by Date: Re: Should Cocoa Apps have splash screens at all ?
  • Next by Date: Best Place To Save States
  • Previous by thread: Re: How to retrieve currencies list
  • Next by thread: Re: How to retrieve currencies list
  • Index(es):
    • Date
    • Thread