2016-10-10 30 views
1

此代码工作正常,但如果我更改我的设备语言,这也显示Rs所以什么正确的方式来获得货币符号?在Android中获取货币符号的正确方法是什么?

public void displayTotlaPrice() { 
    TextView totalPriceTextView = (TextView) findViewById(R.id.total_Price); 
    totalPriceTextView.setText("Rs" + displayCalculatePrice()); 
} 
+1

也许这个答案可能会帮助你。 http://stackoverflow.com/a/36258674/1388715 – Amulya

+0

也看看http://stackoverflow.com/a/14685495/3496570 – Nepster

回答

0

以下变量存储在string.xml

<string name="Rs">\u20B9</string> 

现在叫它如下,无论你想显示Rs符号,

textView.setText(getResources().getString(R.string.Rs) + "500"); 
1
Locale locale = Locale.getDefault(); 
    Currency currency = Currency.getInstance(locale); 
    String symbol = currency.getSymbol().replaceAll("\\w", ""); 
0

可以使用,

Locale swedishLocale = new Locale("sv", "SE"); 
    Currency currency = Currency.getInstance(swedishLocale); 
    System.out.println("Symbol: " + currency.getSymbol()); 

欲了解更多详情,请访问display the currency for a locale

+0

谢谢。有效。 –

1

试试这个,希望它有效。

yourString= NumberFormat.getCurrencyInstance().format(yourNumber); 

NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(); 
String cur = currencyFormatter.format(yourValue); 

特定

yourString= NumberFormat.getCurrencyInstance(new Locale("en", "AU")).format(yourNumber); 

数目将格式化基于设备的语言。

详细信息:

How to get currency symbol by currency name?

Currency