Template:percent: Difference between revisions
From Thesaurus Inscriptionum Raeticarum
Jump to navigationJump to search
Martin Braun (talk | contribs) No edit summary |
Martin Braun (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<noinclude> | <noinclude>[[description::This template serves to calculate and display percentages.]] It awaits two values: the fraction number and the sum. An optional third value can be given as number of positions after the comma (default is 2). | ||
[[description::This template serves to calculate and display percentages.]] It awaits two values: the fraction number and the sum. | |||
=== Examples === | === Examples === | ||
*The code <code><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|5|20}}</nowiki></code> will display "{{{{PAGENAME}}|5|20}}". | *The code <code><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|5|20}}</nowiki></code> will display "{{{{PAGENAME}}|5|20}}". | ||
*The code <code><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|5|20|3}}</nowiki></code> will display "{{{{PAGENAME}}|5|20|3}}". | |||
[[Category:Text Module]] | [[Category:Text Module]] | ||
</noinclude><includeonly>{{#vardefine: template_percent_n | {{{1|}}} }}{{#vardefine: template_percent_all | {{{2|}}} }}{{#ifeq: {{#var: template_percent_n }}||{{#vardefine: template_percent_n | 0 }} }}{{#ifeq: {{#var: template_percent_all }}||{{#vardefine: template_percent_all | 0 }} }}{{#ifeq: {{#var: template_percent_all }}|0||{{#vardefine: template_percent_percent | {{#expr: {{#var: template_percent_n }} / {{#var: template_percent_all }} }} }}{{#vardefine: template_percent_percent | {{#expr: {{#var: template_percent_percent }} * 10000 }}}}{{#vardefine: template_percent_percent | {{#expr: | </noinclude><includeonly>{{#vardefine: template_percent_n | {{{1|}}} }}{{#vardefine: template_percent_all | {{{2|}}} }}{{#vardefine: template_round | {{{3|2}}} }}{{#ifeq: {{#var: template_percent_n }}||{{#vardefine: template_percent_n | 0 }} }}{{#ifeq: {{#var: template_percent_all }}||{{#vardefine: template_percent_all | 0 }} }}{{#ifexpr: {{#var: template_round }} <1|{{#vardefine: template_round | 0 }} }}{{#ifeq: {{#var: template_percent_all }}|0||{{#vardefine: template_percent_percent | {{#expr: {{#var: template_percent_n }} / {{#var: template_percent_all }} }} }}{{#vardefine: template_percent_percent | {{#expr: {{#var: template_percent_percent }} * 10000 }}}}{{#vardefine: template_percent_percent | {{#expr: {{#var: template_percent_percent }} / 100 }}}}{{#vardefine: template_fraction| {{#sub: {{#explode: {{#var: template_percent_percent }}|.|1}} |0|{{#var: template_round}} }} }}{{#explode: {{#var: template_percent_percent }}|.|0}}{{#ifexpr: {{#var: template_round }} >0|.{{#pad: {{#var: template_fraction}}|{{#var: template_round }}|0|right }}}} %}}</includeonly> |
Revision as of 07:52, 21 September 2014
This template serves to calculate and display percentages. It awaits two values: the fraction number and the sum. An optional third value can be given as number of positions after the comma (default is 2).
Examples
- The code
{{percent|5|20}}
will display "25.{{#pad: |2|0|right }} %". - The code
{{percent|5|20|3}}
will display "25.{{#pad: |3|0|right }} %".