To format a currency value, you can use the
NumberFormat.getCurrencyInstance method. However, that method is not very flexible—it returns a formatter for a single currency. Suppose you prepare an invoice for an American customer in which some amounts are in dollars and others are in Euros. You can’t just use two formatters
NumberFormat dollarFormatter = NumberFormat.getCurrencyInstance(Locale.US); NumberFormat euroFormatter = NumberFormat.getCurrencyInstance(Locale.GERMANY);
Your invoice would look very strange, with some values formatted like $100,000 and others like 100.000 €. (Note that the Euro value uses a decimal point, not a comma.)
Instead, use the
Currency class to control the currency ...