Java Internalization - Parse Numbers



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;

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"));
   }
}

Output

It will print the following result.

100.76
10076
Print
Advertisements