在这个例子中,我们展示了对不同语言环境中存在的数字的解析.
IOTester.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