2013-12-17 57 views
1

我需要知道如何使用ICU4C版本52 C API來顯示區域設置貨幣符號和代碼。即($ - USD)使用ICU C API顯示區域設置貨幣符號?

+0

其實我不是C專家。我有一個使用ICU4J製作的程序來顯示所有語言環境信息。貨幣/日期和時間格式/是和沒有字符串...等。我需要與C API類似的東西。 –

+0

我有ICU源代碼並構建了它的測試,但無法找到正確的方法來使用。 –

+0

你有沒有試過看[文檔](http://www.icu-project.org/apiref/icu4c/)? –

回答

0

如何做到這一點可能有多種方法。這裏有一個,我覺得應該工作(未經測試):

Get the number formatformat 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); 
+0

如何在不格式化數字的情況下打印貨幣代碼和符號本身? –

+0

@AyaR .:您可以使用['unum_getTextAttribute'](http://www.icu-project.org/apiref/icu4c/unum_8h.html#a497b8a591fbac7c2d2e604f06a403be1)['UNUM_CURRENCY_CODE']從語言環境中獲取貨幣ISO代碼(http://www.icu-project.org/apiref/icu4c/unum_8h.html#a9d3fc41af40c7a4437230943eb265725)。如果沒有真正格式化數字,我沒有辦法獲得國家代碼。 – wilx

0

或者,更直接,使用ucurr_getName()UCURR_SYMBOL_NAME選擇。您也可以使用ucurr_forLocale()ucurr_forLocaleAndDate()獲取貨幣代碼而不需要格式化程序。請注意,區域設置可能有多種貨幣。