The below set variable outputs the sum of 6 and 2. This works fine, but only works with whole numbers. How, if possible, could I output values with decimal points. ie: 6.2+2.4 outputting 8.6.

Set /a S=6×2

%S%

Thanks

Mark

## Sum of two decimal values

**Moderator:** DosItHelp

### Re: Sum of two decimal values

for /F "delims=" %%G IN ('powershell -command "2.4 + 6.2"') do set "result=%%G"

### Re: Sum of two decimal values

The command processor has a limitation when it comes to floating point arithmetic. Have a look at this workaround:

https://www.dostips.com/DtTipsArithmeti ... atingPoint

Note: You can get your decimal back with string manipulation on the result.

https://www.dostips.com/DtTipsArithmeti ... atingPoint

Note: You can get your decimal back with string manipulation on the result.

### Re: Sum of two decimal values

Thanks for the quick responses.

@atfon. l was reading the workaround you linked whilst you were replying. What exactly do you mean by string manipulation to recover the decimal point?

Thanks

Mark

@atfon. l was reading the workaround you linked whilst you were replying. What exactly do you mean by string manipulation to recover the decimal point?

Thanks

Mark

### Re: Sum of two decimal values

Hello Mark. You can extract the first digit and the last digit:

https://www.dostips.com/DtTipsStringMan ... LeftString

For the first digit, set "first=%str:~-1%" and for the last set "last=%str:~0,1%". Then you can set the entire term as set "whole=%first%.%last.%"

There are likely easier ways to do this that the Experts on this site could point out to you. For example, Squashman's powershell example or VBScript.

### Re: Sum of two decimal values

Thanks for that.

I'm incorperating into ffmpeg scripts so will take a closer look at the best approach for my needs.

Mark

I'm incorperating into ffmpeg scripts so will take a closer look at the best approach for my needs.

Mark