Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default DecimalFormat class

    DecimalFormat class is a very useful class that number formatting and parsing options. Example below shows a use of DecimalFormat class to format an Integer.

    Java Code:
    int numb = 3;
    String rptNumb;
    DecimalFormat df = new DecimalFormat("000");
    rptNumb = df.format(numb);
    System.out.println(rptNumb);

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default

    It could also be done using the Formatter class:

    Java Code:
    System.out.printf("Number = %03d", 3);
    
    String number = String.format("%03d", 3);
    System.out.println("Number = " + number);

Similar Threads

  1. Replies: 0
    Last Post: 04-02-2008, 07:04 AM
  2. Replies: 0
    Last Post: 02-17-2008, 09:03 AM
  3. Replies: 0
    Last Post: 02-17-2008, 09:01 AM
  4. Inner class accessing outer class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 08:59 AM
  5. Replies: 5
    Last Post: 01-03-2008, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •