Java DecimalFormatSymbols create from Locale en-US

Description

Java DecimalFormatSymbols create from Locale en-US

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);/*from w w  w .j  a  v a 2 s .  c  o  m*/
    String bizarre = weirdFormatter.format(12345.678);
    System.out.println(bizarre);


  }
}



PreviousNext

Related