Java DecimalFormat create from custom DecimalFormatSymbols

Description

Java DecimalFormat create from custom DecimalFormatSymbols

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;

public class Main {
  public static void main(String[] args) throws Exception {
    Locale currentLocale = new Locale("en", "US");

    DecimalFormatSymbols mySymbols = new DecimalFormatSymbols(currentLocale);
    mySymbols.setDecimalSeparator('|');
    mySymbols.setGroupingSeparator('^');
    String strange = "#,##0.###";
    DecimalFormat weirdFormatter = new DecimalFormat(strange, mySymbols);
    weirdFormatter.setGroupingSize(4);//  w  ww.  j av a  2s .  co  m
    String bizarre = weirdFormatter.format(12345.678);
    System.out.println(bizarre);


  }
}



PreviousNext

Related