DecimalFormatSymbols Class

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

Example

Open Compiler

importjava.text.DecimalFormat;importjava.text.DecimalFormatSymbols;publicclassI18NTester{publicstaticvoidmain(String[] args){String pattern ="#,###.###";double number =126473.4567;DecimalFormat decimalFormat =newDecimalFormat(pattern);System.out.println(decimalFormat.format(number));DecimalFormatSymbols decimalFormatSymbols =newDecimalFormatSymbols();
      decimalFormatSymbols.setDecimalSeparator(';');
      decimalFormatSymbols.setGroupingSeparator(':');

      decimalFormat =newDecimalFormat(pattern, decimalFormatSymbols);System.out.println(decimalFormat.format(number));}}

Output

It will print the following result.

126,473.457
126:473;457

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *