Search code examples
clocalecurrencyicu

Display locale currency symbol using ICU C API?


I need to know how to use the ICU4C version 52 C API to display the locale Currency Symbol and code. i.e. ($ - USD)


Solution

  • There is probably more than one way how to do this. Here is one, that I think should work (untested):

    Get the number format and format the value using it:

     UErrorCode success = U_ZERO_ERROR;
     UNumberFormat *nf;
     const char* myLocale = "fr_FR";
    
     // get locale specific number format
     nf = unum_open( UNUM_CURRENCY, myLocale, success );
    
     // use it to format the value
     UChar buf[100];
     unum_formatDouble  (nf, 10.0, buf, 100, NULL, &success);   
    
     // close the format handle
     unum_close(nf);