# [pk_math_percentage]

 Link pk_math_percentage Author Pier Kuipers Category Math Version 6.x License Public Domain Posted 10 Jan 2006 Updated 16 Jan 2006 More by this author...

#### Description

tag returns the percentage of two numbers

#### Sample Usage

```Examples:

Without precision:
['[']pk_math_percentage: 5, 2[']'] = [pk_math_percentage: 5, 2]
['[']pk_math_percentage: 5.82, 2[']'] = [pk_math_percentage: 5.82, 2]
['[']pk_math_percentage: 5, 2.73[']'] = [pk_math_percentage: 5, 2.73]
['[']pk_math_percentage: 5.82, 2.73[']'] = [pk_math_percentage: 5.82, 2.73]
['[']pk_math_percentage: 13, 67[']'] = [pk_math_percentage: 13, 67]

With precision:
['[']pk_math_percentage: 5, 2, 1[']'] = [pk_math_percentage: 5, 2, 1]
['[']pk_math_percentage: 5.82, 2, 2[']'] = [pk_math_percentage: 5.82, 2, 2]
['[']pk_math_percentage: 5, 2.73, 3[']'] = [pk_math_percentage: 5, 2.73, 3]
['[']pk_math_percentage: 5.82, 2.73, 4[']'] = [pk_math_percentage: 5.82, 2.73, 4]
['[']pk_math_percentage: 13, 67, 5[']'] = [pk_math_percentage: 13, 67, 5]

```

#### 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.

```[email protected]
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */)
modified by bil corry ([email protected]
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */)
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;

?>
```