how to Multiply a decimal value with -1 in batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
gari
Posts: 1
Joined: 27 Mar 2014 12:49

how to Multiply a decimal value with -1 in batch

#1 Post by gari » 27 Mar 2014 13:01

Hi

I am having a tab delimited file
col1 col2 col3 col4
123 677 778 89.9999
222 677 778 989.999
223 777 778 989.999

when col2 first number equal to 6 ,then i have to multiply col4 with -1 (ie col4 * -1).

Please help me to write the batchscript.

I wrote the scrit its truncating the values.
Thanks
Gari

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: how to Multiply a decimal value with -1 in batch

#2 Post by Squashman » 27 Mar 2014 13:19

Batch SET command does not support floating point arithmetic.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: how to Multiply a decimal value with -1 in batch

#3 Post by Squashman » 27 Mar 2014 13:25

Why would you multiply by -1. All you have to do is put a negative sign in front of the number if you are multiplying by -1.

If you really want to try and multiply with floating point numbers then give Judago's Str_Math.bat file a try.
http://judago.webs.com/mathsbyteconversion.htm

aGerman
Expert
Posts: 4744
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to Multiply a decimal value with -1 in batch

#4 Post by aGerman » 27 Mar 2014 13:31

Could be done using string manipulation. If the first character is a minus then remove it. Otherwise prepend a minus.

Code: Select all

if "%float:~,1%"=="-" (set "float=%float:~1%") else set "float=-%float%"


Regards
aGerman

Post Reply