Java I18n 简明教程

Java Internationalization - Format Currencies

在此示例中,我们将根据美国语言环境和丹麦语言环境格式化货币。

Example

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

public class I18NTester {
   public 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

它将打印以下结果。

kr 100,76
$100.76