Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set customize currency in java?

I tried to make manual currency. Here is my code

DecimalFormat df = new DecimalFormat();
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setCurrencySymbol("$");
dfs.setGroupingSeparator('.');
dfs.setDecimalSeparator('.');
df.setDecimalFormatSymbols(dfs);
System.out.println(df.format(3333454));

Program output is

3.333.454

Why the currency symbol I set didn't appear?

like image 928
greenthunder Avatar asked May 10 '12 15:05

greenthunder


1 Answers

Try this:

NumberFormat df = NumberFormat.getCurrencyInstance();
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setCurrencySymbol("$");
dfs.setGroupingSeparator('.');
dfs.setMonetaryDecimalSeparator('.');
((DecimalFormat) df).setDecimalFormatSymbols(dfs);
System.out.println(df.format(3333454));
like image 197
mprivat Avatar answered Sep 28 '22 00:09

mprivat