how to do division and rounding within the string?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hoda
Posts: 1
Joined: 06 Nov 2016 15:12

how to do division and rounding within the string?

#1 Post by hoda » 06 Nov 2016 15:17

Hi all,
I am new in scripting and I'm working with a tool which is exactly like windows cmd. My input text file is :

age=min;age_1D_param_min_64;meas_time =

My batch file reads the lines from this input and splits the lines by “ ; ” then executes a function with the token and age file from the second field and after all parses the output for the third line.
in the following you can see my current batch file:

Code: Select all

 
    setlocal EnableDelayedExpansion
    for /f "tokens=1,2,3* delims=;" %%a in (input.txt) do (
   REM create token file
   echo.%%a>current.tok
    sinoparam -p D:\product\%%b 0x0100001F current.tok> out.txt
    for /f %%y in ('findstr /C:"%%c" out.txt ^| sed "s/.*%%c .............. )do SET RESULT=%%y
    echo.%%a;%%b;%%c;!RESULT!>>finaloutput.csv
    )
    GOTO :EOF

now I have problem with one string in out.txt which is the result of executing my function:

meas_time =31.9999
in my batch file I want to do the followings:

1.find the value in string dActual_age =31.9999 by findstr/C
2. if the value is lower than 1000 round it and show the result
3. if it’s greater than 1000 first divide it by 32 and then round the result

Does anyone know how I can do this ?
thanks for any help!
HOda
Last edited by aGerman on 07 Nov 2016 01:48, edited 1 time in total.
Reason: code tags added

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

Re: how to do division and rounding within the string?

#2 Post by aGerman » 07 Nov 2016 02:00

The command line interpreter does only know integral values. It cannot calculate decimale numbers. You have to use a 3rd party tool or another scripting language.

Steffen

Post Reply