Currency.getSymbol会给我一个主要的符号(例如美元的“$”)但是我想获得次要单位(例如英镑的“p”或美元的美分符号),而不是写我自己的样子上表。
是否有标准,即以内置方式执行此操作?
答案 0 :(得分:0)
我想建议这种情况使用自定义custom currency format
。使用DecimalFormat
个NumberFormat
或java.text.*
个public class CurrencyFormatExample {
public void currencyFormat(Locale currentLocale) {
Double currency = new Double(9843.21);
NumberFormat currencyFormatter;
String currencyOut;
currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
currencyOut = currencyFormatter.format(currency);
System.out.println(currencyOut + " " + currentLocale.toString());
}
public static void main(String args[]) {
Locale[] locales = new Locale[]{new Locale("fr", "FR"),
new Locale("de", "DE"), new Locale("ca", "CA"),
new Locale("rs", "RS"),new Locale("en", "IN")
};
CurrencyFormatExample[] formate = new CurrencyFormatExample[locales.length];
for (int i = 0; i < locales.length; i++) {
formate[i].currencyFormat(locales[i]);
}
}
}
有很多例子。
实施例
9Â 843,21 â?¬ fr_FR
9.843,21 â?¬ de_DE
CAD 9.843,21 ca_CA
RSD 9,843.21 rs_RS
Rs.9,843.21 en_IN
Out put:
Locale locale = Locale.UK;
Currency curr = Currency.getInstance(locale);
// get and print the symbol of the currency
String symbol = curr.getSymbol(locale);
System.out.println("Symbol is = " + symbol);
参考here:
次要货币更新
Symbol is = £
输出:
{{1}}