String processing in windows batch files: How to pad value with leading zeros?

前端 未结 7 680
时光取名叫无心
时光取名叫无心 2020-11-27 19:07

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

7条回答
  •  青春惊慌失措
    2020-11-27 19:37

    The single line

    IF 1%Foo% LSS 100 SET Foo=0%Foo%
    

    will get you what you want for numbers in the range that you specify. It does not change values in the subset 0-9 if they are already single-padded.

提交回复
热议问题