Results 1 to 5 of 5
  1. #1
    tomiu is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Default integer with leading zero?!

    Hi,

    is it possible to output an integer with a leading zero??

    01,02,03...


    String.format and DecimalFormat are OK but both return String, and when i convert the String in Int then the leading zeros disappear...

    thx in advance
    tomiu

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    That's what happens, an int never has leading zeros. Only the String representation can display a leading zero.

  3. #3
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    what do you mean by output? most likely, your output is a string anyways.

  4. #4
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    Can he use char to do this?

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Who cares? A String is a wrapped char[]
    Last edited by PhHein; 04-22-2009 at 09:48 PM.

Similar Threads

  1. Inverting integer
    By gusgol in forum New To Java
    Replies: 27
    Last Post: 04-20-2009, 04:06 PM
  2. How to display numbers with leading zeros
    By Java Tip in forum java.lang
    Replies: 1
    Last Post: 06-14-2008, 06:36 PM
  3. Breaking down an integer
    By Emily in forum New To Java
    Replies: 1
    Last Post: 03-06-2008, 06:39 PM
  4. Integer vs int
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-14-2007, 09:13 PM
  5. How to display numbers with leading zeros
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:34 PM

Posting Permissions

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