Convert string to integer in batch file

I have a variable read from a file:

%var%=13,145

      

I want to add this value to another value:

set /a %var%=%var%+5

      

but the result 13+5

is not 13145+5

.

How can I remove this "," from my string?

0


source to share


1 answer


Don't add commas.

set var=13145

      

And also when assigning to a variable, don't put it around %

set /a var=%var% + 5   (Or simply set /a var += 5)

      

Test:

@echo off
set var=13145
set /a var=%var% + 5
echo %var%

      



Output:

13150

      

Update

Another solution is to remove these commas with replacement:

set var=13,145
set /a var=%var:,=% + 5

      

+4


source







All Articles