how to convert string into an integer in a batch file ?

user1386966 picture user1386966 · Dec 9, 2012 · Viewed 12.9k times · Source

I have this piece of batch file :

@echo off
set  xx=7
echo the version is %xx%

I wand to use it in a pre-build event in VS2010 - as an integer :

MY_INT = $(xx)

but it's value is a string , how can I convert the string value into an integer value in the batch file?

thanks!

Answer

dbenham picture dbenham · Dec 9, 2012

Environment variables (batch variables) are always strings; they cannot be stored as integers.

The SET command with the /A option can parse integral numbers from strings, perform arithmetic operations, and store the integral result in an environment variable. But the final result is still a string representation of the final number.

Type help set or set /? from a command prompt for more info about the SET /A option.