Trying to create a batch program (I have no other option but only use batch) that can accept a decimal input, the input is only specific up to two decimal places. My problem is how I can round-off the output to improve accuracy. For example the user input is 100.77*0.80, the answer is 80.616, I can only output 80.61 and not 80.616, I want an output of 80.62. And my bigger problem is that the decimal answer will be used to subtract from the original amount which will cause a Mathematical mistake in the decimal level. The answer will be 80.61 and 20.16. Here's my program:
@echo off
setlocal EnableDelayedExpansion
set decimals=2
set /A one=1, decimalsP1=decimals+1
for /L %%i in (1,1,%decimals%) do set "one=!one!0"
:getFee
set /P "Amt=Enter the Amount (100.00): "
set /P "Disc=Enter the Discount Percentage: "
if "!Amt:~-%decimalsP1%,1!" equ "." goto AmtDeci
:getNumber
goto NoDeci
:AmtDeci
set "fpA=%Amt:.=%"
set "fpB=%Disc:.=%"
set /A mul=fpA*fpB/one
set discout=!mul:~0,-2!.!mul:~-2!
echo The Discount is: %discout%
set /A "fpD=%discout:.=%"
set /A sub=fpA-fpD
set Amtout=!sub:~0,-%decimals%!.!sub:~-%decimals%!
echo The Amount less discount is: %Amtout%
pause
Exit /B
:NoDeci
set /a discout=%Amt%*%Disc%/100
set /a Amtout=%Amt%-discout
echo The Amount less Discount is: %Amtout%
echo The Discount is: %discout%
pause