# Batch Programming: Bug in converting Integer from String!?



## B.K. (Apr 19, 2020)

Hi, I´ve got a problem in converting a simple string into an integer:
Try following lines

set "String=04"
set /a Zahl=String
echo Zahl:%Zahl% aus %String% (Zahl=4, how expected) Ok with strings from 01 ... 07

set "String=08"
set /a Zahl=String
echo Zahl:%Zahl% aus %String% (Zahl=0 !!!) the same with string=09

Any Explanation?


----------



## SpywareDr (Mar 31, 2014)

No explanation but, if you were to:

set Zahl=%String%

then the value in Zahl will be the same as the one in String.


----------



## managed (May 24, 2003)

Try it without the leading zero.


----------



## B.K. (Apr 19, 2020)

Hi, thanks for the answer.
The command - set Zahl=%String% - suggested in the first anwer ist still not working for "08" and "09" and the string I have to convert is with leading zero. Per example the cents after the comma.


----------



## SpywareDr (Mar 31, 2014)

Your:

set /a Zahl=String​
is different from my:

set Zahl=%String%​
and results in a different outcome.


----------



## B.K. (Apr 19, 2020)

Thanks again, and yes, I remarked the difference. The problem is, that in your case I´ll get the right string "08" or "09" back into the string variable Zahl and it´s not possible to do further calculation (addition etc.) with Zahl.
Or do you see a solution?? Very welcome for that!


----------



## SpywareDr (Mar 31, 2014)

SET String=08
SET Zahl=%String%
IF %Zahl% LSS 10 SET Zahl=%Zahl:~-1%​
Zahl starts as "08" and ends up as "8".
Should work for any two digit number less than 10.


----------



## B.K. (Apr 19, 2020)

Thank you four your work and suggestion!
I already have a workaround like yours. But imo microsoft should work at this basic command so that the string converting in the range from "01" to "09" should always work in the SAME way!


----------



## SpywareDr (Mar 31, 2014)

So true. But, good luck in trying to convince them to do so. They still have yet to respond to me about a bug in MS-DOS 3.0 that almost drove me off the edge of the planet. (The problem was gone in version 4.0 though).


----------

