我有问题获得国家货币,我通过这些代码在数据库中有国家代码我必须在java中获取国家代码我如何为此制作代码请建议我.我试着用这个例子,但它不起作用.
class Utils {
public static SortedMap<Currency, Locale> currencyLocaleMap;
static {
currencyLocaleMap = new TreeMap<Currency, Locale>(
new Comparator<Currency>() {
public int compare(Currency c1, Currency c2) {
return c1.getCurrencyCode().compareTo(
c2.getCurrencyCode());
}
});
for (Locale locale : Locale.getAvailableLocales()) {
try {
Currency currency = Currency.getInstance(locale);
currencyLocaleMap.put(currency, locale);
} catch (Exception e) {
}
}
}
public static String getCurrencySymbol(String currencyCode) {
Currency currency = Currency.getInstance(currencyCode);
System.out.println(currencyCode + ":-"
+ currency.getSymbol(currencyLocaleMap.get(currency)));
return currency.getSymbol(currencyLocaleMap.get(currency));
}
}
public class GetCurrency {
public static void main(String[] …Run Code Online (Sandbox Code Playgroud) 此代码工作正常,但如果我更改我的设备语言,这也会显示 Rs 那么获取货币符号的正确方法是什么?
public void displayTotlaPrice() {
TextView totalPriceTextView = (TextView) findViewById(R.id.total_Price);
totalPriceTextView.setText("Rs" + displayCalculatePrice());
}
Run Code Online (Sandbox Code Playgroud)