Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:08:19+00:00 2026-06-14T09:08:19+00:00

in a Windows cmd batch file (.bat), how do i pad a numeric value,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:08:21+00:00Added an answer on June 14, 2026 at 9:08 am

    There’s a two-stage process you can use:

    REM initial setup
    SET X=5
    
    REM pad with your desired width - 1 leading zeroes
    SET PADDED=0%X%
    
    REM slice off any zeroes you don't need -- BEWARE, this can truncate the value
    REM the 2 at the end is the number of desired digits
    SET PADDED=%PADDED:~-2%
    

    Now PADDED holds the padded value. If there’s any chance that the initial value of X might have more than 2 digits, you need to check that you didn’t accidentally truncate it:

    REM did we truncate the value by mistake? if so, undo the damage
    SET /A VERIFY=1%X% - 1%PADDED%
    IF NOT "%VERIFY%"=="0" SET PADDED=%X%
    
    REM finally update the value of X
    SET X=%PADDED%
    

    Important note:

    This solution creates or overwrites the variables PADDED and VERIFY. Any script that sets the values of variables which are not meant to be persisted after it terminates should be put inside SETLOCAL and ENDLOCAL statements to prevent these changes from being visible from the outside world.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A windows batch file ( called.bat or called.cmd ) can be called from another
I have a windows batch cmd *.cmd file that runs sql, as part of
In Windows cmd batch, I try to call a batch file: call .\%%R\scenery\list bgl.bat
Is it possible to close Windows Explorer from CMD? I have a batch that
trying to run a simple batch file in windows 2008 task scheduler call cleanup.bat
Using Windows XP, I created a batch-file that takes two files as arguments, and
I have a batch file that creates a scheduled task using schtasks like this:
I have a batch file run.bat that requires many arguments for it to run.
I've got a windows batch file, with a few sub-routines in it something like
I'd like to write a batch file that logs data. Each time it runs,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.