Results 1 to 4 of 4

Thread: [Resolved] Add a Leading Zero to an Integer?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Resolved [Resolved] Add a Leading Zero to an Integer?

    I want to know how to format an integer so that it always displays as two digits, so if the number is 5, it adds a leading 0 as 05. This is to display time. I tried using DecimalFormat, but it doesn't seem to be doing what I want it to, and I get errors half the time.

    Any suggestions?
    Last edited by The Hobo; Dec 8th, 2004 at 03:16 PM. Reason: Resolved
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552

    Re: Add a Leading Zero to an Integer?

    Code:
            NumberFormat f=new DecimalFormat("00");
            System.out.println(f.format(5));
    ?

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Add a Leading Zero to an Integer?

    I think you need to use SimpleDecimalFormat, as DecimalFormat is abstract.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Add a Leading Zero to an Integer?

    Quote Originally Posted by brown monkey
    Code:
            NumberFormat f=new DecimalFormat("00");
            System.out.println(f.format(5));
    ?
    This is what I came up with as well. Thank you.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width