Reputation: 9296
I'm trying to format a String value to a valid currency double as follows
NumberFormat currency=NumberFormat.getCurrencyInstance();
currency.parse("10").doublevalue();
The problem is that I got back a negative number I got -10!. So is there any thing wrong with this code?
Thanks
Upvotes: 0
Views: 847
Reputation: 9110
I think you're misunderstanding the role of NumberFormat a little bit.
You can simply call:
double d= Double.parseDouble("10");
NumberFormat currency=NumberFormat.getCurrencyInstance();
System.out.println(currency.format(d));
For me, this prints out £10.00, and that's the string it would expect to be passed into the parse method
HTH
Upvotes: 2