Java 国际化 - 解析数字
示例
在此示例中,我们展示了如何解析不同语言环境中的数字。
import java.text.NumberFormat; import java.text.ParseException; import java.util.Locale; public class I18NTester { public static void main(String[] args) throws ParseException { Locale enLocale = new Locale("en", "US"); Locale daLocale = new Locale("da", "DK"); NumberFormat numberFormat = NumberFormat.getInstance(daLocale); System.out.println(numberFormat.parse("100,76")); numberFormat = NumberFormat.getInstance(enLocale); System.out.println(numberFormat.parse("100,76")); } }
输出
它将打印以下结果。
100.76 10076