无法在Java 7
中获取少数货币代码的货币符号和区域代码。示例:货币代码。
AFN,
AMD,
ANG,
AOA,
AUD,
AWG,
AZN, etc..
并尝试使用DecimalFormat.getAvailableLocales()
代替NumberFormat.getAvailableLocales()
,但没有用。
以下是获取货币符号的代码。
package com.test.testandbackups;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;
public class CurrencyUtils {
public static void main(String args[]) throws Exception {
String currencyCode = "INR";
String ss = currencySymbol(currencyCode);
System.out.println(ss);
}
public static String currencySymbol(String currencyCode) {
String currencySymbol = null;
currencySymbol = Currency.getInstance(currencyCode).getSymbol(
getLocale(currencyCode));
return currencySymbol;
}
private static Locale getLocale(String currencyCode) {
for (Locale locale : NumberFormat.getAvailableLocales()) {
String code = NumberFormat.getCurrencyInstance(locale)
.getCurrency().getCurrencyCode();
if (currencyCode.equals(code)) {
return locale;
}
}
return null;
}
}