Batch files allows only 32bit integer calculations , though this can be bypassed with different approaches.
As the powershell is installed by default on every windows system from 7/2008 and above it can be used for more complex calculations:
@echo off set "expression=(2+3)*10/1000" for /f %%# in ('"powershell %expression%"') do set result=%%# echo %result%
Mind the additional double quotes in the
for /f which prevent brackets conflicts with the for command syntax.
Potential issue is that powershell is much slower than using wsh/vbscript/jscript due to the loading of the .net framerwork
WSH/JScript is installed on every windows system since NT so using it for more complex calculations makes it pretty portable. JScript is easier for combining it with batch file :
@if (@[email protected]) @then @echo off set "expression=2*(2+3)/1000" for /f %%# in ('cscript //nologo //e:jscript "%~f0" "%expression%"') do set result=%%# echo %result% :: more batch code exit /b %errorlevel% @end WScript.Echo(eval(WScript.Arguments(0)));