#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Posts
    3
    Rep Power
    0

    How to covert a 2 digit number to a 4 digit number?


    Hi all,

    Anyone know what to use to convert an 2 digit integer e.g. 93, to a 4-digit integer e.g. 0093?

    Thanks :-)
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    chicago, il
    Posts
    9
    Rep Power
    0
    convert 93 to an Integer, then concatenate it with 00, then convert back to a string. note, you can't keep "0093" in an int or a float as it will truncate the extra zeroes.


    so,

    int a = 93;
    Integer b= new Integer(a);
    StringBuffer c = new StringBuffer("00" + b.toString());
    string d = c.toString();


    this would be a wordy way of doing it, but it illustrates what needs to be done.

IMN logo majestic logo threadwatch logo seochat tools logo