[pk_math_percentage]

Description

Link: [pk_math_percentage]
Author: Pier Kuipers
Category: Math
Version: 6.x
License: Public Domain
Posted: Jan. 10, 2006
Updated: Jan. 16, 2006
More by this author...
tag returns the percentage of two numbers

Parameters

none


Sample Usage

<pre>
<b>Examples:</b><br>
<br>
Without precision:<br>
['[']pk_math_percentage: 5, 2[']'] = <b>[pk_math_percentage: 5, 2]</b><br>
['[']pk_math_percentage: 5.82, 2[']'] = <b>[pk_math_percentage: 5.82, 2]</b><br>
['[']pk_math_percentage: 5, 2.73[']'] = <b>[pk_math_percentage: 5, 2.73]</b><br>
['[']pk_math_percentage: 5.82, 2.73[']'] = <b>[pk_math_percentage: 5.82, 2.73]</b><br>
['[']pk_math_percentage: 13, 67[']'] = <b>[pk_math_percentage: 13, 67]</b><br>
<br>
With precision:<br>
['[']pk_math_percentage: 5, 2, 1[']'] = <b>[pk_math_percentage: 5, 2, 1]</b><br>
['[']pk_math_percentage: 5.82, 2, 2[']'] = <b>[pk_math_percentage: 5.82, 2, 2]</b><br>
['[']pk_math_percentage: 5, 2.73, 3[']'] = <b>[pk_math_percentage: 5, 2.73, 3]</b><br>
['[']pk_math_percentage: 5.82, 2.73, 4[']'] = <b>[pk_math_percentage: 5.82, 2.73, 4]</b><br>
['[']pk_math_percentage: 13, 67, 5[']'] = <b>[pk_math_percentage: 13, 67, 5]</b><br>
</pre>
						

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_percentage
by pier kuipers (pier@visualid.com)
modified by bil corry (bil@lasso.biz)
returns the percentage of two numbers
usage: [pk_math_percentage: total, part, precision]
(precision is optional)
*/
	if: !(lasso_tagexists:'pk_math_percentage');

		define_tag:'pk_math_percentage',
			-required='total',
			-required='part',
			-optional='precision';
	
			did we get a precision?
			if:!(local_defined:'precision');
				nope, set it to zero
				local:'precision' = 0;
			/if;
			
			make sure precision is an integer
			#precision = integer: #precision;	
	
			calculate the percentage
			local:'percentage' = decimal:#part / decimal:#total * decimal:100;
	
			format the percentage
			#percentage->(setformat: -precision=#precision);
	
			return the percentage
			return: #percentage;
	
		/define_tag;
		
	/If;
     
?>

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net