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

Java Internapzation - DecimalFormatSymbols Class


Previous Page Next Page  

Using DecimalFormatSymbols class, the default separator symbols, grouping separator symbols etc. can be changed. Following example is illustrating the same.

IOTester.java

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

pubpc class I18NTester {
   pubpc static void main(String[] args) {
      String pattern = "#,###.###";
      double number = 126473.4567;

      DecimalFormat decimalFormat = new DecimalFormat(pattern);

      System.out.println(decimalFormat.format(number));
   

      DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
      decimalFormatSymbols.setDecimalSeparator( ; );
      decimalFormatSymbols.setGroupingSeparator( : );

      decimalFormat = new DecimalFormat(pattern, decimalFormatSymbols);

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

Output

It will print the following result.

126,473.457
126:473;457
Print