English 中文(简体)
JAVA I18N - Parsing Numbers
  • 时间:2024-12-22

Java Internapzation - Parse Numbers


Previous Page Next Page  

In this example, we re showcasing parsing of number present in different locale.

IOTester.java

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

pubpc class I18NTester {
   pubpc 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"));
   }
}

Output

It will print the following result.

100.76
10076
Print