[pk_math_average]

Description

Link: [pk_math_average]
Author: Pier Kuipers
Category: Math
Version: 6.x
License: Public Domain
Posted: Jan. 10, 2006
Updated: Jan. 16, 2006
More by this author...
Returns the average of an array of numbers

Parameters

none


Sample Usage

[math_average: (Array: 2, 3.51, 4), 2] = 3.17
[math_average: (Array: 2, 3.51, 4)] = 3
[math_average: (Array: 11, 11, 15, 26, 25, 11, 12), 5] = 15.85714
[math_average: (Array: 11, 11, 15, 26, 25, 11, 12)] = 16
[variable: 'myArray' = (Array: 5.82, 12, 365, 3)]
[math_average: $myArray, 2] = 96.45
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?LassoScript

/* 
pk_math_average
Returns the average of an array of numbers

Usage: [pk_math_average: number_array, precision]

(precision is optional)

Examples below
Written by Pier Kuipers
Dublin, Ireland 
May 2003
*/

	if: !(lasso_tagexists:'pk_math_average');

		define_tag:'pk_math_average',
			-required='number_array',
			-optional='precision';
			if:!(local_defined:'precision');
				local:'precision' = 0;
			/if;
			#precision = integer: #precision;	
			local:'number_array_total' = #number_array -> get: 1;
			local:'loopcount' = 2;
			loop: ((#number_array -> Size) - 1);
				#number_array_total += (decimal:(#number_array -> get: #loopcount));
				#loopcount += 1;
			/loop;
			local:'average' = (#number_array_total / (#number_array -> Size));
			#average->(setformat: -precision=#precision);
			return: #average;
		/define_tag;
		
	/If;

?>

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net