Reputation: 3
I am currently working in batch. I want to know a way to multiply or add with percents and/or decimals.
Example:
set /a wcexpt= %wcexpt% * ??
Every time I try this:
set /a wcexpt= %wcexpt% * .005
it results in a 0.
When I try this:
set /a wcexpt= %wcexpt% * %5
it results in "missing operand"
Upvotes: 0
Views: 1531
Reputation: 67216
You may simulate operations with decimals using only integer numbers in a very simple way. For example:
@echo off
set /P "wcexpt=Enter value: "
rem Get 5% of wcexpt:
set /a percent=wcexpt * 5
rem Show result:
echo The 5%% of %wcexpt% is %percent:~0,-2%.%percent:~-2%
Output:
C:\> test
Enter value: 1234
The 5% of 1234 is 61.70
Of course, a much more detailed simulation that include all arithmetic operations is possible. See this post for further details.
Upvotes: 0
Reputation: 80073
The short answer is that batch uses integers only, so you must convert your formulae to use integers.
Also, the integers are limited to ~ +/- 2**31.
You can extend the range - but it takes some mathematical gymnastics and will be extremely slow.
Upvotes: 1
Reputation: 96
I tried this and it is working it is giving the result as 1
set /a wcexpt = 20
set /a wcexpt= (wcexpt * 5)/100
echo %wcexpt%
Upvotes: 0