[HPADM] SUMMARY How to find percent in a script

From: Brendan Doherty (bdoherty@itl.ca)
Date: Thu Apr 24 2003 - 11:45:34 EDT


Hi thanks for all the responses.. it was an easy problem - just I could not see it.

here is one way to get % .
Brendan

The expr command works on integers and when dividing gives you modulus.
Because 20 divided by 80 is 0 remainder 20 that is why you are getting 0.
Try this:
VALUEONE=20
VALUETWO=80
PERCENT=`expr \( $VALUEONE \* 100 \) / $VALUETWO`
echo $PERCENT
You might like to change the echo statement to:
echo ${PERCENT}%
so you get a nice percent sign as well.

Brendan Doherty wrote:

> Hi I keep on getting 0 ... seems like it does not like to divide ...
> anyone know how to calculate a percent from to #'s
>
> VALUEONE=20
> VALUETWO=80
>
> PERCENT=`expr $VALUEONE / $VALUETWO \* 100 `
>
> echo $PERCENT
>
> ----
> I receive 0 ,,, it should be .25..
> 20/80 * 100 =0.25 ; seems like to 20/80 is returning 0.
>
> thanks
>
> --
> ---> Please post QUESTIONS and SUMMARIES only!! <---
> To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
> Name: hpux-admin@dutchworks.nl Owner: owner-hpux-admin@dutchworks.nl
>
> Archives: ftp.dutchworks.nl:/pub/digests/hpux-admin (FTP, browse only)
> http://www.dutchworks.nl/htbin/hpsysadmin (Web, browse & search)

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:29 EDT