在本例中,我們根據美國區域設定和丹麥語區域設定格式化貨幣。
檔案:IOTester.java -
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));
}
}
執行上面範例程式碼,得到以下結果 -
kr 100,76
$100.76