Home / How-to Guides / How to Calculate using dos command line in windows

How to Calculate using dos command line in windows

Generally for doing any calculation on windows, we use calculator or some application  but other than that, we can also use Dos i.e Command Prompt. Calculating arithmetic expressions on command line is more easy and expressive on command line.  Because when solving some complex logic, command line comes very handy.

DOS Shell has a built-in  mini calculator to perform simple arithmetic calculation on 32 bit signed integer. The “SET” with /a switch Dos command  is used to perform calculation on command line.

To know more on 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 support other types of operators. while using 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.


Operation performed

< >


* / % + –


<< >>

Logical shift


Bitwise AND


Bitwise exclusive OR


Bitwise OR

= *= /= %= += -= &= ^= |= <<= >>=



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 4 instead of 4.5

About Kroshan

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.
  • Anonymous

    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

  • Anonymous

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

  • rick

    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.