Home / How-to Guides / How to Calculate using Windows Command Line

How to Calculate using Windows Command Line

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.

set /a expressionCalculate using dos command line in windows

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.

OperatorOperation performed
< >Grouping
* / % + –Arithmetic
<< >>Logical shift
&Bitwise AND
^Bitwise exclusive OR
|Bitwise OR
= *= /= %= += -= &= ^= |= <<= >>=Assignment
,Expression separator

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

About Roshan Karkera

Roshan Karkera a.k.a. k.roshan. Blogger by passion and software engineer by profession. He believes in sharing knowledge, which made him to start his own blog. He is very much keen & passionate about new technology & Science. If you'd like to connect with him, follow at Google plus or Twitter.

5 comments

  1. 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

  2. hey thats really cool, i can use dos as calculator now!!

  3. that really worked..

  4. 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.

  5. 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.

Leave a Reply

Your email address will not be published.