在本例中,我们根据美国区域设置和丹麦语区域设置格式化货币。
文件: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