[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1516.0. "Need to get percent" by XCUSME::BERNIER (Jean-Paul) Wed Nov 06 1991 10:26

    Could somebody please let me know how to figure percent using DCL.
    TX
T.RTitleUserPersonal
Name
DateLines
1516.1BEING::EDPAlways mount a scratch monkey.Wed Nov 06 1991 11:1117
    Re .0:
    
    Percent of what?  If you have two numbers, x and y, and what to find
    out what percent x is of y, then use the command:
    
    	WRITE SYS$OUTPUT x*100/y
    
    That's equivalent to multiplying x by 100 and dividing by y.  That will
    truncate the answer.  You can get more decimal places by multiplying by
    a thousand or more and mentally placing a decimal point in the answer,
    but at some point you will run into the limitation where you have
    multiplied x by something too big, so that it exceeds 2147483647, the
    largest positive integer DCL can handle.  You can also get the answer
    rounded off instead of truncated by using (x*whatever+y/2)/y.
    
    
    				-- edp
1516.2percentages?ZFC::deramoI've seen it raining fire in the sky.Wed Nov 06 1991 11:2851
>    Could somebody please let me know how to figure percent using DCL.

You can do integer arithmetic with

	$ write sys$output 1700 / 39
	43

So 17 is roughly 43% of 39.  Of course, the division truncates
instead of rounding off, as you can see with

	$ write sys$output 99 / 10
	9

To get less than half to truncate, and half or more to round up,
you can add in half of the denominator...

	$ write sys$output (99 + 5) / 10
	10

In a case like 39, you can't take half of it and still be an integer
but you can double both numerator and denominator, with something like

	$ write sys$output (2 * 17 * 100 + 39) / (2 * 39)
	44

So it would round up.  (Note: 17 is 43.5897...% of 39).  That is kind
of a mess to type in, though.  If you add an extra 0 to both numerator
and denominator of the fraction, the 39 becomes a 390 and is now even
and can be halved

	$ write sys$output (17000 + 390/2) / 390
	44

For more decimal places, multiply by a power of ten before dividing
(be extremely careful mixing this with the + 390/2 method)

	$ write sys$output 1700 * 1000 / 39
	43589

(corresponds to 43.589% (which is truncated)) or

	$ write sys$output (1700 * 1000 * 10 + 390/2) / 390
	43590

(corresponds to 43.590% (which is rounded up)).

Dan

p.s. Truncation, rounding down and rounding up all refer to how DCL
behaves with positive integers, not negative ones.  I haven't looked
into that.
1516.3ZFC::deramoI've seen it raining fire in the sky.Wed Nov 06 1991 11:293
Oops, notes collision. :-)

Dan
1516.4note collision insurance policySTAR::ABBASIWed Nov 06 1991 12:1414
    ref .3
    ok, that is it, Dan: i've tallied the number of times you 'note collided'
    and it seems according to my calculations that you've just broke
    the record and just exceeded the maximum allowable collision per person.
    
    so we are therefore will be raising your note usage insurance rates
    premium to cover medical coverage of injured notes.
    
    this time it seems no note got hurt, but iam afraid that one of those days,
    a major notes collision might occur, and that might result in one or more
    notes might get hurt real bad, i cant bear the thought of that.
                                                                        
    /nasser
    
1516.5ZFC::deramoI've seen it raining fire in the sky.Wed Nov 06 1991 14:121
re .-1 :-)
1516.6Let's call a code a codeVMSDEV::HALLYBFish have no concept of fireWed Nov 06 1991 14:205
    For those of you not "in the know", Dan D'eramo is actually a 92MB LISP
    program executing in Hudson.  That's why it collides with humans, and
    tends to frequent the more scientific conferences.
    
      John
1516.7%LISP-I-SPELLZFC::deramoI've seen it raining fire in the sky.Wed Nov 06 1991 17:227
>    For those of you not "in the know", Dan D'eramo is actually a 92MB LISP
>    program executing in Hudson.  That's why it collides with humans, and
>    tends to frequent the more scientific conferences.

Dan spells his last name "D'Eramo" with a capital "E".

Dan