Java String format int type

Description

Java String format int type

 P:Syntax
public static String format(String format, Object... args)
public class Main {
  public static void main(String[] args) {

    int number = 123;
    String numberAsString = String.format("%d", number);
    System.out.println(numberAsString);
    numberAsString = String.format("%05d", number);
    System.out.println(numberAsString);
    numberAsString = String.format("%010d", number);
    System.out.println(numberAsString);
    // w  ww. j  av a2  s  .  c  o  m
    number = 1234567;
    numberAsString = String.format("%,d", number);
    System.out.println(numberAsString);

  }
}



PreviousNext

Related