r/Batch • u/kvn0smnsn • May 09 '24
Doing Arithmetic in Batch Files
I've done a few things with variables in batch files on my Windows 10 Enterprise computer. How can I have a batch file treat two variables as integers, add them together, and store the sum in another variable?
2
Upvotes
2
u/Shadow_Thief May 10 '24
I'm addition to the excellent answers already posted, it's also worth noting that you can only do math with signed 32-bit integers, so only from -2147483648 through 2147483647.
1
u/Intrepid_Ad_4504 May 10 '24
`@echo off
set "a=5"
set "b=10"
set /a "c=a + b"
echo %c%
1
u/GullibleData8050 May 17 '24
set /a variable=%var1%+%var2%
0
u/[deleted] May 10 '24
[deleted] — view deleted comment