English 中文(简体)
JAVA I18N - DecimalFormat Class
  • 时间:2024-11-05

Java Internapzation - DecimalFormat Class


Previous Page Next Page  

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;

pubpc class I18NTester {
   pubpc 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