[HPADM] SUMMARY How to find percent in a script
From: Brendan Doherty (bdoherty@itl.ca)
Date: 04/24/03
- Previous message: Dave T.: "[HPADM] Installing RAM on an N4000 w/ 11.0"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 24 Apr 2003 11:45:34 -0400 From: "Brendan Doherty" <bdoherty@itl.ca> To: "hpux-admin@dutchworks.nl" <hpux-admin@dutchworks.nl>
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)
- Previous message: Dave T.: "[HPADM] Installing RAM on an N4000 w/ 11.0"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|