Question

Write the code to format number 12345.67812345.678 in U.S. currency

Solution

Verified
Answered 1 year ago
Answered 1 year ago

We can write the code to format number 12345.678 in U.S. currency using the getCurrencyInstance method to which we parse the desired locale, and then format it with the format() method into which we also parse the amount that is to be formatted.

NumberFormat currencyFormat =NumberFormat.getCurrencyInstance(Locale.US);
System.out.println(currencyFormat.format(12345.678));

Create an account to view solutions

Create an account to view solutions

More related questions