Reputation:
I would like to create a number with N digits.
Example;
myVar=543
and I would like it with 6 digits so myVar will be 000543
myVar=44345 will be 044345
myVar=1 will be 0000001
...
I do that with Batch, so just with Windows Batch commands.
Upvotes: 1
Views: 4039
Reputation: 16256
Stephan's method works. It can also be done using PowerShell formatting.
SET "N=123.4"
FOR /F %%n IN ('powershell -NoLogo -NoProfile -Command "([double]%N%).ToString('000000')"') DO (SET "NZ=%%n")
ECHO %NZ%
Upvotes: 0
Reputation: 56188
add 6 zeros at the front of the number and then cut the last 6 characters:
set myVar=51
echo 1: %myVar%
set myVar=000000%myvar%
echo 2: %myVar%
set myVar=%myVar:~-6%
echo 3: %myVar%
Upvotes: 2