Java NumberFormat create from Locale

Description

Java NumberFormat create from Locale

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

public class Main {
  public static void main(String[] args) throws Exception {

    Locale[] locales = { new Locale("en", "US"), new Locale("de", "DE"), new Locale("fr", "FR") };

    for (int i = 0; i < locales.length; i++) {
      NumberFormat nf = NumberFormat.getNumberInstance(locales[i]);
      DecimalFormat df = (DecimalFormat) nf;
      df.applyPattern("###,###.###");
      String output = df.format(123456.789);
      System.out.println(output + "  from  " + locales[i].toString());
    }/*w w w  .  j  a  v a  2s . c  om*/
  }
}



PreviousNext

Related