web analytics
Wednesday, June 18, 2025
HomeHow-to GuidesHow 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

Roshan Karkera
Roshan Karkera
Roshan Karkera is a passionate blogger and a software engineer by profession, driven by a love for technology, science, and continuous learning. With a strong belief in sharing knowledge, he started this blog to inspire and inform readers through simple, insightful content. When he's not coding or exploring the latest in tech, you’ll find him writing about ideas that matter. Connect with him on Twitter or your favorite social platform to stay updated.
RELATED ARTICLES

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

Please enter your comment!
Please enter your name here

Most Popular