Link to home
Start Free TrialLog in
Avatar of marcelo27
marcelo27

asked on

add leading zeroes

I need to add leading zeroes to an input box.
For example, the user enters "2" , I need to convert to a three digit number eg."002".
If the user enters a three digit number leave it alone.

thanks for your help .
SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of marcelo27
marcelo27

ASKER

Im not sure why var num = "2"?
The user can enter any numerical value. If the user enters a one or double digit number zeroes need to be added. The maximum length of string is 3.
marcelo27:

i was giving an example and num is what you have to assign, my primary objective is to let you know that my function works :) if i didn't put the num there and an example value, you wouldn't be able to see the working code and it would be harder to understand.

hope that explains why i put "2" as num, you can put and assign any number from anywhere to the num variable.