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

    Join Date
    Mar 2003
    Posts
    2
    Rep Power
    0

    Javascript function to affix zeroes


    I need to make or find a function or something in Javascript which will affix zeroes to the beginning of a number to make it a certain length.
    For example, if the number is 15, and i want it to be 5 digits long, the function should output the string "00015".
    Thanks in advance.
  2. #2
  3. Second highest poster :p
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2001
    Posts
    7,322
    Rep Power
    32
    just get the length of the string (varname.length) and then subtract that from the length you want it to be. Then use a for loop to add 0's to the variable/string until you reach the difference.
    - Andreas Koepke

    Koepke Photography

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    2
    Rep Power
    0
    thanks. if you can't tell, i am very new to javascript.

IMN logo majestic logo threadwatch logo seochat tools logo