Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help on adding float number 2

Status
Not open for further replies.

vuakhobo

Technical User
Apr 22, 2004
41
US
I have main program calling Run_Time function which return number of minutes in decimal point. I tried to add the total minutes but having problem with it. Can someone help me ...

example:
pmart@satpai30:/vframe/STRODS/indata/log>file_detail.sh F381 F382
3.42 minutes to load F381
/vframe/STR/bin/file_detail.sh[3]: stack empty: syntax error
2.62 minutes to load F382
/vframe/STR/bin/file_detail.sh[3]: stack empty: syntax error
------------------------------
Total:

Add ()
{
rx=`echo 5 k $rx + $1 | dc`
}
#Main Program
#get_tempfile SQLFILE $VF_SQL sql # The .sql file used by sqlplus
SQLFILE="$VF_TEMP/$SCRIPT_NAME.sql"

if test $# != 0
then
until test $# == 0
do
Run_Time=$(Run_Time $1)
echo "$Run_Time minutes to load $1"
Total=$(Add $Run_Time)
shift
done
fi
echo "------------------------------"
echo "Total:$Total"
 
> rx=`echo 5 k $rx + $1 | dc`
dc uses postfix notation, not infix.
So you would write 2 3 + rather than 2 + 3

Eg.
Code:
$ echo $a $b
2 3
$ echo $a $b + p | dc
5
The 'p' command causes the result to be printed.

However, many shells now have built-in arithmetic, so this may be possible (and more efficient)
Code:
$ echo $a $b
2 3
$ let c=$a+$b
$ echo $c
5

--
 
Salem, good advice on dc, however for the latter part I don't know of any shells that support floating point arithmetic.

Annihilannic.
 
Depending on the type of unix your using (it works on AIX ksh93 shell but not ksh).

ksh
a=((1.5*1.5))
echo $a
1

ksh93
a=((1.5*1.5))
echo $a
2.25


Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Thanks mrn, now I do. :)

It doesn't work in pdksh 5.2.14 on Linux, but it does with a recent ksh binary from David Korn's web site (kornshell.com).

Annihilannic.
 
vuakhobo, you may try something like this:
#Main Program
#get_tempfile SQLFILE $VF_SQL sql # The .sql file used by sqlplus
SQLFILE="$VF_TEMP/$SCRIPT_NAME.sql"
for i; do
Run_Time=$(Run_Time $i)
echo "$Run_Time minutes to load $i"
done | awk '{print;t+=$1}END{print "Total:",t}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

It works great!! Thank you very much...

pmart@satpai30:/vframe/STR/bin>file_detail.sh F381 F382 F383 F384 F385 F386 C080
------------------------------
3.42 minutes to load F381
2.62 minutes to load F382
1.65 minutes to load F383
1.62 minutes to load F384
1.75 minutes to load F385
0.63 minutes to load F386
92.9 minutes to load C080
Total: 104.59
 
PHV,
awk '{print;t+=$1}END{print "Total:",t}'

The result is correct but there is one thing that could mislead the users is .59 ... it is not 59 seconds but rather .59 of a minute .. Is there a way that I could multiply 60 to .59 to get second.
 
You may try this:
printf "Total: %dmin%dsec\n",int(t),60*(t-int(t))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
Yeah!!!! it works thank you very very much....

Cam on nhieu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top