Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Aug 2002 01:28:26 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        "Christopher J. Umina" <uminac@216-164-225-145.c3-0.wth-ubr2.sbo-wth.ma.cable.rcn.com>
Cc:        FreeBSD Question Mailing List <questions@FreeBSD.ORG>
Subject:   Re: expr replacement
Message-ID:  <20020823062826.GF34104@dan.emsphone.com>
In-Reply-To: <20020823021838.V67143-100000@216-164-225-145.c3-0.wth-ubr2.sbo-wth.ma.cable.rcn.com>
References:  <20020823021838.V67143-100000@216-164-225-145.c3-0.wth-ubr2.sbo-wth.ma.cable.rcn.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Aug 23), Christopher J. Umina said:
> Hi guys & gals,
> 
> 	I'm writing a simple shell script that finds percentages for me.
> The problem here is that when I do the division with expr I always get a
> result of 0 since it's below 1.  Is there a replacement for this or am I
> just doing it wrong?  Take a look..  This is my command.
> 
> percentage=`expr $dirttl / $totalsongs`

To return a number from 0..100:

percentage=`expr $dirttl \* 100 / $totalsongs`

If you want a fractional result you'll have to use the bc command,
which is an arbitrary-precision calculator.

-- 
	Dan Nelson
	dnelson@allantgroup.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020823062826.GF34104>