SET (/A) Command (floating point)

The SET /A command enables the value of an arithmetical expression to be stored into a variable.

This manual pages is only about the use of the /A of the SET command. To learn more about the general use of the command, please see the SET manual page.


SET [/a] variable=expression

Computes the value of the arithmetical expression expression and stores it into variable. Unlike the original batch command of cmd, the SET command also provide support for floating point numbers, if floating-point values are given inside the expression. This behaviour is explained in detail in the Toogling floating-point expression section.

The = sign can be prefixed with one the of the supported binary operator, in which case, SET /a stores the result of variable binary_operator (expression) inside variable. For instance:

:: equivalent to SET /a var=var+3
SET /a var+=3

The given expression must consist of a sequence of operands separated by operators.


Operands represent the numbers to which a sequence of operations will be applies. Operands must be of one the following types:


The SET /a provides a wide variety of operators that can be used with both integers and floating point numbers.

The topmost precedence is given to the 3 following unary operators (an unary operator is an operator that only takes one operand to the right):

Then, the following binary operators are processed (a binary operator is an operator that takes two operands):

Operators have the following precedence (from greatest to lowest):

To avoid precedence issues, use the parenthesis ( and ).


Available functions are:


Finally, the following constants are defined

Toogling floating-point expressions

The use of floating-point arithmetics is triggered by the use of one of the following features :

If none of these conditions are met and the use of floating point is required, one can force it using an operation that does not change the result but use floats (for example adding 0.0) as in the following sample:

:: By default this use integers arithmetics
SET /a var=a/b
:: Trigger the use of floating point arithmetics
SET /a var=a/b+0.0


Integers wich are usually bound between -2 147 483 648 and +2 147 483 647.

Floating-point numbers offer a much greater range, between 2,2250738585072014e-308 à 1,7976931348623157e+308. However, this gain on range causes a loss of precision because of approached computing.


It is possible to encounter preciseness bug as floating-point number have a finite precision of about 15 decimal places. As a result some expression may be subject to approximation errors when dealing with numbers several orders of magnitude away from one another. Here is an example:


Computing this expression using floating points arithmetics will lead to a precision error as the result would be 0 even though it is clearly 1. This happen because 10^60 is several orders of magnitude greater than 1. Changing slightly the expression can fix this issue :



This command uses a modified version of the GNU libmatheval library.


Available since, before the support of expressions was incomplete, supporting neither the % operating system nor functions.

Not compatible with cmd.exe that does not support floating point arithmetics.

See also

SET Command, SET (/a) Command (integers)