Jump to content

Template:Percentage/doc: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m syntaxhighlight, {{tlx}}, {{para}}
 
(11 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}
{{high-use}}
{{tsh|pct|percent}}
{{lua|Module:Percentage}}
{{lua|Module:Percentage}}
<!-- PLEASE ADD CATEGORIES AT THE BOTTOM OF THIS PAGE. -->
<!-- PLEASE ADD CATEGORIES AT THE BOTTOM OF THIS PAGE. -->
==Usage==
==Usage==
<tt><nowiki>{{percentage | numerator | denominator | decimals to round to (zero or greater) }}</nowiki></tt>
{{tlx|percentage | numerator | denominator | decimals to round to (zero or greater) }}


==Limitations==
==Limitations==
Line 9: Line 11:


==Examples==
==Examples==
* <nowiki>{{Percentage | 1 | 3 | 0 }}</nowiki> yields {{Percentage | 1 | 3 | 0 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 3 | 0 }}</syntaxhighlight> yields {{Percentage | 1 | 3 | 0 }}
* <nowiki>{{Percentage | 1 | 3 | 2 }}</nowiki> yields {{Percentage | 1 | 3 | 2 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 3 | 2 }}</syntaxhighlight> yields {{Percentage | 1 | 3 | 2 }}


Negative values can be used:
Negative values can be used:
* <nowiki>{{Percentage | -1 | 3 }}</nowiki> yields {{Percentage | -1 | 3 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | -1 | 3 }}</syntaxhighlight> yields {{Percentage | -1 | 3 }}


Normal operation is to cut off all decimal zeroes from right in rounding:
Normal operation is to cut off all decimal zeroes from right in rounding:
* <nowiki>{{Percentage | 1 | 5 | 2 }}</nowiki> yields {{Percentage | 1 | 5 | 2 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 5 | 2 }}</syntaxhighlight> yields {{Percentage | 1 | 5 | 2 }}
* <nowiki>{{Percentage | 1111 | 10000 | 4 }}</nowiki> yields {{Percentage | 1111 | 10000 | 4 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1111 | 10000 | 4 }}</syntaxhighlight> yields {{Percentage | 1111 | 10000 | 4 }}
Add '''<tt>|pad=yes</tt>''' to always get as many decimals as specified, padding with zeroes where needed:
Add '''{{para|pad|yes}}''' to always get as many decimals as specified, padding with zeroes where needed:
* <nowiki>{{Percentage | 1 | 5 | 2 | pad=yes }}</nowiki> yields {{Percentage | 1 | 5 | 2 | pad=yes }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 5 | 2 | pad=yes }}</syntaxhighlight> yields {{Percentage | 1 | 5 | 2 | pad=yes }}
* <nowiki>{{Percentage | 1111 | 10000 | 4 | pad=yes }}</nowiki> yields {{Percentage | 1111 | 10000 | 4 | pad=yes }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1111 | 10000 | 4 | pad=yes }}</syntaxhighlight> yields {{Percentage | 1111 | 10000 | 4 | pad=yes }}
Third parameter can also be given through <tt>|pad=N</tt>:
Third parameter can also be given through {{para|pad|N}}:
* <nowiki>{{Percentage | 111 | 1000 | pad=4 }}</nowiki> is same as <nowiki>{{Percentage | 111 | 1000 | 4 | pad=yes }}</nowiki> and yields {{Percentage | 111 | 1000 | pad=4 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 111 | 1000 | pad=4 }}</syntaxhighlight> is same as <syntaxhighlight lang="wikitext" inline>{{Percentage | 111 | 1000 | 4 | pad=yes }}</syntaxhighlight> and yields {{Percentage | 111 | 1000 | pad=4 }}


Default denominator is 100:
Default denominator is 100:
* <nowiki>{{Percentage | 20 }}</nowiki> yields {{Percentage | 20 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 20 }}</syntaxhighlight> yields {{Percentage | 20 }}


Default precision is zero:
Default precision is zero:
* <nowiki>{{Percentage | 1 | 3 }}</nowiki> yields {{Percentage | 1 | 3 }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 3 }}</syntaxhighlight> yields {{Percentage | 1 | 3 }}


Override the percent symbol
Override the percent symbol
* <nowiki>{{Percentage | 1 | 3 | % = &amp;nbsp;percent}}</nowiki> yields {{Percentage | 1 | 3 | % = &nbsp;percent}}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 3 | % = &nbsp;percent}}</syntaxhighlight> yields {{Percentage | 1 | 3 | % = &nbsp;percent}}


Use a prescribed number of significant figures
Use a prescribed number of significant figures
* <nowiki>{{Percentage | 1 | 4000 | sigfig = 3}}</nowiki> yields {{Percentage | 1 | 4000 | sigfig = 3}}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 4000 | sigfig = 3}}</syntaxhighlight> yields {{Percentage | 1 | 4000 | sigfig = 3}}


Use a prescribed number of significant figures with small percentages
Use a prescribed number of significant figures with small percentages
* <nowiki>{{Percentage | 1 | 40000000 | sigfig = 3}}</nowiki> yields {{Percentage | 1 | 40000000 | sigfig = 3}}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 40000000 | sigfig = 3}}</syntaxhighlight> yields {{Percentage | 1 | 40000000 | sigfig = 3}}


Use a prescribed number of significant figures with small percentages without scientific notation
Use a prescribed number of significant figures with small percentages without scientific notation
* <nowiki>{{Percentage | 1 | 40000000 | sigfig = 3 | nonscinote = y}}</nowiki> yields {{Percentage | 1 | 40000000 | sigfig = 3 | nonscinote = y }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 1 | 40000000 | sigfig = 3 | nonscinote = y}}</syntaxhighlight> yields {{Percentage | 1 | 40000000 | sigfig = 3 | nonscinote = y }}


Use a prescribed number of significant figures with large percentages
Use a prescribed number of significant figures with large percentages
* <nowiki>{{Percentage | 40000000 | 2 | sigfig = 3}}</nowiki> yields {{Percentage | 40000000 | 2 | sigfig = 3}}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 40000000 | 2 | sigfig = 3}}</syntaxhighlight> yields {{Percentage | 40000000 | 2 | sigfig = 3}}


Use a prescribed number of significant figures with large percentages without scientific notation
Use a prescribed number of significant figures with large percentages without scientific notation
* <nowiki>{{Percentage | 40000000 | 2 | sigfig = 3 | nonscinote = y}}</nowiki> yields {{Percentage | 40000000 | 2 | sigfig = 3 | nonscinote = y }}
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 40000000 | 2 | sigfig = 3 | nonscinote = y}}</syntaxhighlight> yields {{Percentage | 40000000 | 2 | sigfig = 3 | nonscinote = y }}


Dividing by zero will result in "nan" ([[division by zero|undefined]])
==Aliases==
* <syntaxhighlight lang="wikitext" inline>{{Percentage | 0 | 0 | 0 }}</syntaxhighlight> yields {{Percentage | 0 | 0 | 0 }}
* {{Tlx|Pct}}
* {{Tlx|Percent}}


== See also ==
==TemplateData==
{{TemplateData header}}
* {{tl|Percent-done}}
* {{tl|Round}}
* {{tl|Significant figures}}
* {{tl|Fractions and ratios}}
* {{tl|Winning percentage}}
* {{tl|Number and percent}}
<templatedata>
<templatedata>
{
{
Line 64: Line 60:
"1": {
"1": {
"label": "Numerator",
"label": "Numerator",
"description": "The Numerator of the calculated value. The percentage will be calculated as Numerator divided by Demoninator.",
"description": "The Numerator of the calculated value. The percentage will be calculated as Numerator divided by Denominator. Use of comma as a thousands separator is optional.",
"type": "number",
"type": "number",
"required": true
"required": true
Line 70: Line 66:
"2": {
"2": {
"label": "Denominator",
"label": "Denominator",
"description": "The Demoninator of the calculated value. The percentage will be calculated as Numerator divided by Demoninator. Can be left out, in which case 100 will be used as the Demoninator, and the Numerator will be the direct percentage used.",
"description": "The Denominator of the calculated value. The percentage will be calculated as Numerator divided by Denominator. Use of comma as a thousands separator is optional. Can be left out, in which case 100 will be used as the Denominator, and the Numerator will be the direct percentage used.",
"type": "number",
"type": "number",
"suggested": true,
"suggested": true,
Line 101: Line 97:
}
}
</templatedata>
</templatedata>

== See also ==
* {{tl|Number and percent}}
* {{tl|Winning percentage}}
* {{tl|Round}}
* {{tl|Significant figures}}
* {{tl|Fractions and ratios}}
<includeonly><!--
<includeonly><!--
++++ PLEASE ADD CATEGORIES BELOW THIS LINE, THANK YOU. -->{{basepage subpage|
++++ PLEASE ADD CATEGORIES BELOW THIS LINE, THANK YOU. -->{{basepage subpage|

Latest revision as of 01:12, 6 March 2024

Usage

[edit]

{{percentage|numerator|denominator|decimals to round to (zero or greater)}}

Limitations

[edit]

Figures smaller than 0.0001% are shown in scientific notation.

Examples

[edit]
  • {{Percentage | 1 | 3 | 0 }} yields 33%
  • {{Percentage | 1 | 3 | 2 }} yields 33.33%

Negative values can be used:

  • {{Percentage | -1 | 3 }} yields -33%

Normal operation is to cut off all decimal zeroes from right in rounding:

  • {{Percentage | 1 | 5 | 2 }} yields 20%
  • {{Percentage | 1111 | 10000 | 4 }} yields 11.11%

Add |pad=yes to always get as many decimals as specified, padding with zeroes where needed:

  • {{Percentage | 1 | 5 | 2 | pad=yes }} yields 20.00%
  • {{Percentage | 1111 | 10000 | 4 | pad=yes }} yields 11.1100%

Third parameter can also be given through |pad=N:

  • {{Percentage | 111 | 1000 | pad=4 }} is same as {{Percentage | 111 | 1000 | 4 | pad=yes }} and yields 11.1000%

Default denominator is 100:

  • {{Percentage | 20 }} yields 20%

Default precision is zero:

  • {{Percentage | 1 | 3 }} yields 33%

Override the percent symbol

  • {{Percentage | 1 | 3 | % = &nbsp;percent}} yields 33 percent

Use a prescribed number of significant figures

  • {{Percentage | 1 | 4000 | sigfig = 3}} yields 0.0250%

Use a prescribed number of significant figures with small percentages

  • {{Percentage | 1 | 40000000 | sigfig = 3}} yields 00%

Use a prescribed number of significant figures with small percentages without scientific notation

  • {{Percentage | 1 | 40000000 | sigfig = 3 | nonscinote = y}} yields 00%

Use a prescribed number of significant figures with large percentages

  • {{Percentage | 40000000 | 2 | sigfig = 3}} yields 2.00×109%

Use a prescribed number of significant figures with large percentages without scientific notation

  • {{Percentage | 40000000 | 2 | sigfig = 3 | nonscinote = y}} yields 2000000000%

Dividing by zero will result in "nan" (undefined)

  • {{Percentage | 0 | 0 | 0 }} yields nan%

TemplateData

[edit]
This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:Percentage in articles based on its TemplateData.

TemplateData for Percentage

Calculates and displays a percentage value.

Template parameters

ParameterDescriptionTypeStatus
Numerator1

The Numerator of the calculated value. The percentage will be calculated as Numerator divided by Denominator. Use of comma as a thousands separator is optional.

Numberrequired
Denominator2

The Denominator of the calculated value. The percentage will be calculated as Numerator divided by Denominator. Use of comma as a thousands separator is optional. Can be left out, in which case 100 will be used as the Denominator, and the Numerator will be the direct percentage used.

Default
100
Numbersuggested
Decimals3

Number of decimals to round to (zero or greater); if pad is not Yes, 0-digits will be cropped from the end.

Default
0
Numberoptional
Pad / actual number of digitspad

If yes, use all digits given in Decimals. If a number, pad to that number of decimals.

Stringoptional
Significant figuressigfig

If set to a positive integer, the precision of the returned number will be adjusted to match the requested number of significant figures.

Numberoptional
% replacement%

Replacement for % symbol

Example
&nbsp;percent
Stringoptional

See also

[edit]