way way off topic
perryh at pluto.rain.com
perryh at pluto.rain.com
Tue Oct 23 07:22:02 UTC 2012
Olivier Nicole <olivier.nicole at cs.ait.ac.th> wrote:
> On Tue, Oct 23, 2012 at 11:20 AM, Gary Kline <kline at thought.org> wrote:
> > apologies up front for this math type quandary. I had it in
> > a std C program, but 3+ hours of grepping havent found it.
> > I would have bet my last cent that I had a summary Somewhere,
> > but cant find that either.
> >
> > here is the problem as best I can remember it.
> >
> > let's say that john is 8 and his older friend, jim, is 22.
> > how much older is exact percentage terms is jim?
>
> That should be 22/8=2.75
> Jim is 275% older than John
No, a subtraction is needed if we wish to use the term "older".
Suppose Jim were 9; the above approach would give 9/8 => 1.125
so Jim is 113% older than John, which is clearly wrong (although
one could correctly say in that case that John's age is 113% of
Jim's age).
I think the OP is probably looking for
((22 - 8) * 100 + (8/2)) / 8
which will give the answer directly as a correctly-rounded
integral percentage. (For a fractional percentage, use floats
instead of ints and omit the (8/2) part -- but in that case
you probably also want to express the ages in something other
than whole years.)
More information about the freebsd-questions
mailing list