Java int type format via DecimalFormat

Description

Java int type format via DecimalFormat

import java.text.DecimalFormat;

public class Main {
   public static void main(String[] args) {
      int number = 123;
      DecimalFormat df = new DecimalFormat("00000");
      String numberAsString = df.format(number);
      System.out.println(numberAsString);
      //ww  w.  ja va  2  s. c om
      number = 1234567;
      df = new DecimalFormat("#,###");
      numberAsString = df.format(number);
      System.out.println(numberAsString);
   }
}



PreviousNext

Related