How can I use a batch file to loop through non-integer values?
I’m trying to run my application multiple times with different parameters between 0 and 1 as follows:
!! DO NOT RUN THIS !!
set application=C:\path\to\my\application.exe
for /L %%p in (0, 0.05, 1) do (
md %%p
cd %%p
START %application% %%p
cd ..
)
But running the above code sends me into an infinite loop, I guess because for /L is looking for integer arguments and 0.05 is converted to 0.
Is it possible to loop through non-integer values using a batch file?
No it’s not possible, as cmd.exe can’t handle in any way real values.
But you can count integers and calculate later the real value.
The code counts now form 0 to 100.
Each number will prefixed with
00to ensure that each number has at least three digits (like 2->002).Then I take only the last three characters, so all numbers have the same length.
Then the code splits the number into two part
Then
set "num=!prefix!.!postfix!"places the dot between the two parts