In my application, I get a number having leading zeros. I am trying to trim the leading zeros and get the actual number. I tried using /a switch which considers right side of the assignment as an arithmetic expression. So I tried:
SET /a N = 00027
The above gave me the output of 23 which is the decimal equivalent of octal number 27. Then I found this solution online.
SET N = 00027
SET /a N = 1%N%-(11%N%-1%N%)/10
This seems working and is giving the output 27. Is there much easier way to trim the leading zeros in a batch file?
xindicates that you're using an octal number (0x0027indicates a hex number). The only way to remove it is to concatenate a non-zero value on the left to make it appear to be a decimal value and then remove the amount added. (You can see the number formats supported by using a known invalid value in the operation, likeset /a N=d/1, which produces 'Invalid number. Numeric constants are either decimal (17), hexadecimal (0x11), or octal (021).". – Ken White Feb 7 '13 at 23:18