Java Internalization - Parse Numbers


Advertisements

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

Useful Video Courses


Video

Java Date and Time Online Training

16 Lectures 2 hours

Malhar Lathkar

Video

Java Servlet Online Training

19 Lectures 5 hours

Malhar Lathkar

Video

JavaScript Online Training

25 Lectures 2.5 hours

Anadi Sharma

Video

Java Online Training

Most Popular

126 Lectures 7 hours

Tushar Kale

Video

Java Essential Training

119 Lectures 17.5 hours

Monica Mittal

Video

Java Essentials Online Training

76 Lectures 7 hours

Arnab Chakraborty

Advertisements