Hi all,

did this a long time ago but have forgotten.

If I have a number eg 7292 and I want to basically add all the digits to generate the result of 20, how can I accomplish this ?

Thanks for your thoughts

## How to sum digits of a number

**Moderator:** DosItHelp

### Re: How to sum digits of a number

Code: Select all

```
@echo off
setlocal
SET "number=7292"
set "sum=0"
for /F "delims=" %%G IN ('cmd /u /c "echo %number%"^|find /V ""') do (
set /A sum+=%%G
)
echo SUM IS: %sum%
endlocal
pause
```

Code: Select all

```
C:\Users\Squashman\Desktop>sum.bat
SUM IS: 20
Press any key to continue . . .
```

### Re: How to sum digits of a number

Thank you, very much appreciated ! Working like a treat