Hello,
I need some direction in how to get the percentage of two variables in batch. The problem im having is that decimal values less than 0 return a 0 making it impossible to calculate the percentage, or am i just missing something?
_____________________________
@echo off
set intx=0
set inty=100
set intz=25
set /A intx=(%intz%/%inty%)*100
echo percentage is %intx%%
echo.
pause
Batch Percentage Help
Share
the closest you can get is vbscript, which is native to windows. You can write your own calculator using whatever degree of elaboration you have the patience for.
here’s a simple one (calc.vbs):
set con=wscript.stdin
set xx=wscript.stdout
set t=wscript.arguments
op=t(1)
one=t(0)
two=t(2)
select case op
case “/”
out=one/two
case “+”
out=one+two
case “-“
out=one-two
case “*”
out=one*two
end select
xx.writeline(out)
end
and call it like this (to capture the answer to a var):
for /f %%a in (‘cscript /b calc.vbs 12.6 / 18.2’) do set xx=%%a
echo %xx%
::—– end
I was lazy and used separate arguments, so the spaces required between the numbers and operators.
of course you can add as many other operators as you want:
modulo, exponentiation, square roots, etc etc.
I wish cscript could be compiled into .exe, but alas…
i saw some for download but they were either “trials” or $$.