DosTips.com ... for VISTA,XP,NT,Server 2000,Server 2003,Server 2008
Search:
Last update:
Apr 2, 2008

DOS - Arithmetic

How to use SET /A for arithmetic in DOS


DOS - Arithmetic
How to use SET /A for arithmetic in DOS

Floating Point Arithmetic
Working around the limitations of the command processor.

Large Integers
Working around the limitations of the command processor.

Percent
Basic Percent arithmetic.

SET /A
Basic Integer Arithmetic.


TOP
2008-04-01

Floating Point Arithmetic - Working around the limitations of the command processor

Description:
Floating point arithmetic can be achieved by moving the fractions into the integer. I.e. A floating point equitation using values with 3 digits after the dot can be calculated as follows:
Floating Point: 12.055 + 1.001 = 13.056
Integer:        12055 + 1001 = 13056
Script:
1.
2.
set /a y=12055 + 1001
echo.y = %y%
Script Output:
 DOS Script Ouput
y = 13056

TOP
2008-04-01

Large Integers - Working around the limitations of the command processor


TOP
2008-04-01

Percent - Basic Percent arithmetic


TOP
2008-04-01

SET /A - Basic Integer Arithmetic

Description:
The SET /A command can be used for basic arithmetic.
You can write SET /a y=3*x or SET /a y=3*%x%. Both are correct. The command interpreter is smart enough to recognize variables within a formula.
Script:
1.
2.
3.
4.
5.
set /a x=20
set /a y=3*x
set /a y+=140
set /a y/=2
echo.y = %y%
Script Output:
 DOS Script Ouput
y = 100