Internationalizing Currency (I18N with Currency)

Internationalizing Currency (I18N with Currency)

  1. Internationalizing Currency
  2. Example of Internationalizing Currency

As we have internationalize the date, time and numbers, we can internationalize the currency also. The currency differs from one country to another so we need to internationalize the currency.

The NumberFormat class provides methods to format the currency according to the locale. The getCurrencyInstance() method of the NumberFormat class returns the instance of the NumberFormat class.

The syntax of the getCurrencyInstance() method is given below:

  1. public static NumberFormat getCurrencyInstance(Locale locale)

Example of Internationalizing Currency

In this example, we are internationalizing the currency. The format method of the NumberFormat class formats the double value into the locale specific currency.

  1. import java.text.NumberFormat;
  2. import java.util.*;
  3. public class InternalizationCurrency {
  4. static void printCurrency(Locale locale){
  5.  double dbl=10500.3245;
  6.  NumberFormat formatter=NumberFormat.getCurrencyInstance(locale);
  7.  String currency=formatter.format(dbl);
  8.  System.out.println(currency+” for the locale “+locale);
  9. }
  10. public static void main(String[] args) {
  11.     printCurrency(Locale.UK);
  12.     printCurrency(Locale.US);
  13.     printCurrency(Locale.FRANCE);
  14. }
  15. }
download this example
Output:£10,500.32 for the locale en_GB
       $10,500.32 for the locale en_US
       10 500,32 £ for the locale fr_FR
Next TopicJava Interview Questions
java for beginners
java for beginners
java for beginners
CodSir //course // books
...

WikiSir

Internationalizing Currency (I18N with Currency) Internationalizing Currency Example of Internationalizing Currency As we have internationalize the date, time and numbers, we can internationalize the currency also. The currency differs from one country to another so we need to internationalize the currency. The NumberFormat class provides methods to format the currency according to the locale. The getCurrencyInstance() method of the […]

Tags:

....
...