English 中文(简体)
JAVA I18N - Format Currencies
  • 时间:2024-12-22

Java Internapzation - Format Currencies


Previous Page Next Page  

In this example, we re formatting currencies based on US locale and Danish Locale.

IOTester.java

import java.text.NumberFormat;
import java.util.Locale;

pubpc class I18NTester {
   pubpc static void main(String[] args) {
      Locale enLocale = new Locale("en", "US");  
      Locale daLocale = new Locale("da", "DK");

      NumberFormat numberFormat = NumberFormat.getCurrencyInstance(daLocale);

      System.out.println(numberFormat.format(100.76));

      numberFormat = NumberFormat.getCurrencyInstance(enLocale);

      System.out.println(numberFormat.format(100.76));
   }
}

Output

It will print the following result.

kr 100,76
$100.76
Print