Beispiel

public static void main(String[] args){
double value = 12345.678;
Locale defaultLocale = Locale.getDefault();
NumberFormat nf = NumberFormat.getCurrencyInstance(defaultLocale);
String formattedValue = nf.format(value);
System.out.println(formattedValue);
}
Lösung
Verwenden Sie com.ibm.icu.util.Currency (ICU 2.6.1) oder java.util.Currency.
  1. Rufen Sie auf:
    Currency.getInstance (java.lang.String)
  2. Rufen Sie auf:
    java.text.NumberFormat.setCurrency (java.util.Locale)

public static void main(String[] args) {
double value = 12345.678;
Currency currency = Currency.getInstance("EUR"); //$NON-NLS-1$
Locale defaultLocale = Locale.getDefault();
NumberFormat nf = NumberFormat.getCurrencyInstance(defaultLocale);
nf.setCurrency(currency);
String formattedValue = nf.format(value);
System.out.println(formattedValue);
}