Java Internalization - DecimalFormat Class


Advertisements

The java.text.DecimalFormat class is used for formatting numbers as per customized format and as per locale.

Example - Format Numbers

In this example, we're formatting numbers based on a given pattern.

IOTester.java

import java.text.DecimalFormat;

public class I18NTester {
   public static void main(String[] args) {
      String pattern = "####,####.##";
      double number = 123456789.123;
      
      DecimalFormat numberFormat = new DecimalFormat(pattern);

      System.out.println(number);
      
      System.out.println(numberFormat.format(number));
   }
}

Output

It will print the following result.

1.23456789123E8
1,2345,6789.12
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