Reputation: 815
I am trying to display 3000 as €300,0 using the code below :
String formattedString = String.format("%.2€;",3000);
System.out.println("format: "+formattedString);
but result in force close error.
what am I missing?
Upvotes: 2
Views: 175
Reputation: 10555
Try something like this:
import java.text.NumberFormat;
import java.util.Locale;
Locale locale = new Locale("en", "UK");
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);//use Locale.getDefault() if you didn't know the type
System.out.println(fmt.format(100.00));
This will print: £100.00
Upvotes: 0
Reputation: 478
Check out the Java API: NumberFormat. It will show how to use predefined formats top achieve your goal.
Upvotes: 1
Reputation: 308743
I would recommend using a locale-specific currency format instead
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.getDefault());
Better I18N that way.
Upvotes: 4