Generally, for doing any calculation on Windows, we use a calculator or some application, but other than that, we can also use Windows Command Line, i.e., Command Prompt. 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 article, we will see how you can calculate using the Windows Command Line, i.e., Windows Command Prompt.
DOS Shell has a built-in mini calculator to perform the simple arithmetic calculation 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 expression 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.
|* / % + –||Arithmetic|
|<< >>||Logical shift|
|^||Bitwise exclusive OR|
|= *= /= %= += -= &= ^= |= <<= >>=||Assignment|
Note: It overflow values for decimal integer. 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.