2 Replies Latest reply: Aug 15, 2008 10:19 AM by 807589 RSS

    help keeping leading zero String->Long

    807589
      Hello

      I wonder lets say I have a String "09090" how do I convert this String to a Long and keeping leading zero so the Long is 09090?

      /D_S
        • 1. Re: help keeping leading zero String->Long
          807589
          Numeric types like Long (or long) are numbers, not strings, so they have no formatting notions like leading zeroes. If you want to maintain the string "09090" keep the string around, even if you have to parse it as well. By the way, you forgot to describe what your goal is, what you are trying to do and what it has to do with leading zeroes.

          One more: Why does this print false?
          System.out.println(07070 == 7070);
          Hint: this generates a compile-time error:
          System.out.println(09090 == 9090);
          • 2. Re: help keeping leading zero String->Long
            807589
            If what you want is to convert the number back to String for output with leading zeros then you can use, e.g. String.format("%05d", theNumber);

            This willl padd the number to five digits with zeros on the left.