Exemplo:
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;
class NumberFormatComMoeda {
public static void main(String[] args) {
NumberFormat nf = NumberFormat.getCurrencyInstance (new Locale ("pt", "BR"));
double d = 12345678.90;
String s = nf.format (d);
System.out.println (s); // deve imprimir "R$ 12.345.678,90"
// Para os que preferem double:
try {
double d1 = nf.parse (s).doubleValue();
System.out.println (d1); // imprime "1.23456789E7"
} catch (ParseException ex) {
ex.printStackTrace();
}
// Para os que preferem BigDecimal:
((DecimalFormat) nf).setParseBigDecimal(true);
try {
BigDecimal bd = (BigDecimal) (nf.parse(s));
System.out.println (bd); // imprime "12345678.90"
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}