Generally, for doing any calculation on Windows, we open the calculator app or use spreadsheet Excel. However, there’s another powerful tool built right into the operating system that many people overlook, which is the Windows Command Line, also known as Command Prompt.
Yes, you can perform arithmetic calculations directly from the Command Prompt. The Command Prompt isn’t just for running system commands; it is also capable of performing fast and accurate arithmetic operations like addition, subtraction, multiplication, division, and even modulus. Calculating arithmetic expressions on the command line is more straightforward and expressive. Because when solving some complex logic, the command line comes in very handy. In this guide, you’ll learn how to perform simple and complex calculations right from the Windows Command Line without needing any external tool or calculator app.
DOS Shell has a built-in mini calculator to perform simple arithmetic calculations on 32-bit signed integers. The “SET” with /a switch DOS command is used to perform calculations on the command line.
To know more about this command type set /? at the command prompt.
Here are some expressions below
C:\>set /a 3+3 will output 6
C:\>set /a 3*3 will output 9
C:\>set /a 8/4 will output 2
C:\>set /a 2+2 will output 4
C:\>set /a 5*(2/2)+10 will output 15
C:\>set /a (5*2)/2+10 will output 15
C:\>set /a “15>>2” will output 3
It also supports other types of operators. While using a logical or modulus operator, always enclose the expression string in quotes.
The following table lists the operators supported for /a in descending order of precedence.
Operator | Operation performed |
---|---|
< > | Grouping |
* / % + – | Arithmetic |
<< >> | Logical shift |
& | Bitwise AND |
^ | Bitwise exclusive OR |
| | Bitwise OR |
= *= /= %= += -= &= ^= |= <<= >>= | Assignment |
, | Expression separator |
Note: It overflows values for decimal integers. It eliminates the decimal point value and round of the integer. i.e., 9/2 will result in 4 instead of 4.5
thanks for specifying below that it doesn't support flotting point numbers, and i was trying to figuring out y the output i m getting diffrent
hey thats really cool, i can use dos as calculator now!!
that really worked..
I am usually to blogging we actually appreciate your articles. This content has really peaks my interest. I am about to bookmark your blog and keep checking for brand spanking new data.
The fact that it doesn’t accept subdecimals makes it completely unreliable, and therefore useless.
For example: 8/9=0.8888888888888889 but the command line returns 0 (zero).
That is, it omits the digits after the decimal point, and No, it does Νot Round the result.