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

有帮助吗?

解决方案

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);

其他提示

Or, more directly, use ucurr_getName() with the UCURR_SYMBOL_NAME selector. You can also use ucurr_forLocale() or ucurr_forLocaleAndDate() to get the currency code without needing a formatter. Note that there can be multiple currencies for a locale.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top