in a Windows cmd batch file (.bat), how do i pad a numeric value, so that a given value in the range 0..99 gets transformed to a string in the range “00” to “99”. I.e. I’d like to having leading zeros for values lower than 10.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s a two-stage process you can use:
Now
PADDEDholds the padded value. If there’s any chance that the initial value ofXmight have more than 2 digits, you need to check that you didn’t accidentally truncate it:Important note:
This solution creates or overwrites the variables
PADDEDandVERIFY. Any script that sets the values of variables which are not meant to be persisted after it terminates should be put insideSETLOCALandENDLOCALstatements to prevent these changes from being visible from the outside world.