Convert a string to integer in a batch file

后端 未结 1 1999
栀梦
栀梦 2021-01-15 02:56

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

相关标签:
1条回答
  • 2021-01-15 03:04

    Do not add commas.

    set var=13145
    

    And also, when assigning a variable, don't place 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 those commas with substitution:

    set var=13,145
    set /a var=%var:,=% + 5
    
    0 讨论(0)
提交回复
热议问题