Tôi muốn đề xuất cho trường hợp này sử dụng tùy chỉnh custom currency format
. Sử dụng gói DecimalFormat
hoặc NumberFormat
trong số java.text.*
. Có rất nhiều ví dụ cho điều đó.
Ví dụ
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]);
}
}
}
Out đặt:
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
Reference here:
Cập nhật cho đồng tiền nhỏ
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);
Đầu ra:
Symbol is = £
+1 Tôi nghi ngờ là không. BTW, Không phải tất cả các loại tiền tệ đều có một biểu tượng nhỏ. Có ba ký tự cent ¢, ¢ và ₡ –
+1 Bạn có thể sử dụng [Danh sách các quốc gia, lãnh thổ và tiền tệ] (http://publications.europa.eu/code/en/en-5000500.htm) để thực hiện tra cứu bản đồ. – dan
Cá nhân tôi xem [dự án ICU] (http://site.icu-project.org/) hoặc [Joda-Money] (http://joda-money.sourceforge.net/) cho loại này dữ liệu, nhưng cả hai dường như thiếu thông tin cụ thể này. –