Use instead:
NumberFormat nf= NumberFormat.getCurrencyInstance(Locale.US);
문제
I have this block of code
double price = rs.getDouble("price");
NumberFormat nf= NumberFormat.getCurrencyInstance();
String formatedPrice = nf.format(price);
buff.append("( " + formatedPrice + ")");
When I run the code everything works fine but the currency is set to for example: ( C800 ). I guess is because my country has the "Colon" for currency, but that is a thing from the past we now use the Dollar currency. So how can I change the currency to show this: ($400) instead of this (C300). Thanks very much for any help.
해결책
Use instead:
NumberFormat nf= NumberFormat.getCurrencyInstance(Locale.US);
다른 팁
Assuming you are using US dollar you can use NumberFormat.getCurrencyInstance(Locale.US)
You can add a locale as parameter to getCurrencyInstance:
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
You can default it to $
Here is the solution
double price = rs.getDouble("price");
NumberFormat nf= NumberFormat.getCurrencyInstance();
nf.setMaximumFractionDigits(2);
Currency currency = Currency.getInstance(Locale.US);
nf.setCurrency(currency);
String formatedPrice = nf.format(price);
System.out.println("( " + formatedPrice + ")");
Here is the solution