On Sat, 6 Mar 2021 22:19:37 -0500, Tom Del Rosso wrote:
> This is curious.
>
> set x=09
> set /a y=x
>
> results in the answer zero, but it should give the invalid number error.
>
> set /a y=%x%
> does give the expected error.
>
> BTW I like to use
> set /a y=(1%x%-100) ...*/-+...
> as a compact way to remove the zero.
Numbers with leading zero(es) are treated as Octal numbers. So, "8" and "9"
number are invalid Octal numbers.
When SET /A is used with variables only (i.e. no constant), it doesn't
display any error message when it encounters an error. Instead, it simply
set the ERRORLEVEL, then sets the result of the calculation to zero. i.e. a
silent error.
e.g. this causes an error.
set/a 08
This causes a silent error.
dir>nul
echo %errorlevel%
rem above should output: 0
set x=07
set/a x
rem above should output: 7
echo %errorlevel%
rem above should output: 0
set x=08
set/a x
rem above should output: 0
echo %errorlevel%
rem above should output non zero