Method 1: Principle of Two Negatives Make a Positive
@echo off
set /p var=Please enter a negative number:
set /a var=-%var%
echo The absolute value is: %var%
There is an error when calculating numbers with decimals ~ : )
There is an error when calculating positive numbers : )
Method 2: (Negative number) - (Negative number) * 2 = (Absolute value)
@echo on
set /p var=Please enter a negative number:
set /a var=%var%-%var%*2
echo The absolute value is: %var%
Does not support floating-point operations.
Only supports finding the absolute value of a negative number (errors occur when entering a positive number)
Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._