The arithmetic operations of SET /A command are performed over 32-bits integer numbers only; however, you may easily simulate fixed point operations with SET /A if you choose a number of decimal digits and preserve they throughout the operations. For example:
REM Select two decimal digits for all operations
SET /A VAR=250+310
ECHO RESULT: %VAR:~0,-2%.%VAR:~-2%
This method allows you to directly perform addition or subtraction of two "Fixed Point" numbers. Of course, if you want to input numbers in the usual way (with decimal point), you must eliminate the decimal point and left zeros before perform the operations.
You may also directly multiply or divide a FP (fixed point) number by an integer and the result is correct. To multiply or divide two FP numbers we may use an auxiliary variable called ONE with the correct number of decimal places. For example:
rem Set "ONE" variable with two decimal places:
SET ONE=100
rem To multiply two FP numbers, divide the result by ONE:
SET /A MUL=A*B/ONE
rem To divide two FP numbers, multiply the first by ONE:
SET /A DIV=A*ONE/B
Further details at this post.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…