View Full Version : number calculations in batch file


Dos group
09-26-2005, 07:33 PM
I need to do a simple numbers calculation in a bacth file,
90-15. The first digit will always be constant but the second digit is a
variable, called %d1. So I need to calculate 90-%d1. Anyone have a tool to
script this and place the output into another variable, say %d2 ?

William Allen
09-26-2005, 08:31 PM
"Dos group" wrote in message
> I need to do a simple numbers calculation in a bacth file,
> 90-15. The first digit will always be constant but the second digit is a
> variable, called %d1. So I need to calculate 90-%d1. Anyone have a tool to
> script this and place the output into another variable, say %d2 ?

You are unwise to name a variable %D1 since expansion will
be problematical unless you use !%D1! with Delayed Expansion
enabled.

As to simple calculation, see the SET /a command. For help
with this use /?
set /?

If you insist on using %D1 as your variable name, this screen
capture shows typical syntax

============Screen capture Windows 2000 simulated in Win95
C:\WORK>SET %D1=15

C:\WORK>SET /a RESULT=90-!%D1!
75
C:\WORK>ECHO Result is %RESULT%
Result is 75

C:\WORK>
============End screen capture

--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/

Timo Salmi
09-26-2005, 08:53 PM
Dos group wrote:
> I need to do a simple numbers calculation in a bacth file,

61} How can one devise a command line calculator?
136348 Sep 25 13:47 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Dos group
09-26-2005, 09:10 PM
Timo, thanks for the link. I have used some of your stuff in the past. You
have some very nice scripts and wonderful documentation.
William, I was simply using very objective concepts in my email. I actually
used a much different naming convention in my scripts. Anyhow thanks for the
info as it did coincide with the suggestion Timo had as well.

Sincerely,
Rod Harrison
"Timo Salmi" <ts@uwasa.fi> wrote in message
news:u57s3PtwFHA.2960@tk2msftngp13.phx.gbl...
> Dos group wrote:
>> I need to do a simple numbers calculation in a bacth file,
>
> 61} How can one devise a command line calculator?
> 136348 Sep 25 13:47 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
> tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
>
> All the best, Timo
>
> --
> Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
> Department of Accounting and Business Finance ; University of Vaasa
> mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
> Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html