Template:Wins-losses-pct in table: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m syntaxhighlight lang="wikitext"
Added optional third parameter for ties and made to use {Winning percentage} for calculation instead of doing the calc itself.
Line 1: Line 1:
<includeonly>{{{1}}} {{!!}} {{{2}}} {{!!}} {{#ifeq:{{{2}}}|0|{{#ifeq:{{{1}}}|0|–|1.000}}|.{{padleft:{{#expr:({{{1}}}*1000/({{{1}}}+{{{2}}})) round 0}}|3|0}}}}</includeonly><noinclude>
<includeonly>{{{1}}} {{!!}} {{{2}}} {{!!}} {{#if:{{{3|}}}|{{{3}}} {{!!}}}} {{Winning percentage|{{{1|}}}|{{{2|}}}|{{{3|}}}}}</includeonly><noinclude>


==Description==
==Description==
This template produces three wikitable columns that represent wins, losses and a winning percentage as follows:
This template produces three or four wikitable columns that represent wins, losses, optionally ties, and a winning percentage as follows:
: <code><wins> || <losses> || <winning percentage></code>
: <code><wins> || <losses> || <winning percentage></code>
or
where <code>wins</code> comes from parameter 1 to this template, <code>losses</code> comes from parameter 2 and <code><winning percentage></code> is automatically computed based on parameters 1 and 2. Winning percentage is calculated as a three-decimal place value between .000 and 1.000.<ref name=percent />
: <code><wins> || <losses> || <ties> || <winning percentage></code>
where <code>wins</code> comes from parameter 1 to this template, <code>losses</code> comes from parameter 2, <code>ties</code> comes from parameter 3 if present, and <code><winning percentage></code> is automatically computed based on parameters 1 and 2 and 3 if present.<ref name=percent />

Winning percentage is calculated as a three-decimal place value between .000 and 1.000. The value is <code>wins</code> / (<code>wins</code> + <code>losses</code>) for 2 parameters, or (<code>wins</code> + (<code>ties</code> / 2)) / (<code>wins</code> + <code>losses</code> + <code>ties</code>) for 3 parameters. If the total of the parameters is zero, the oercentage is "—".


==Examples==
==Examples==
Line 11: Line 15:
* {{tlx|WinLossPct|0|5}} produces {{Font color|black|#dfdfdf|{{WinLossPct|0|5}}}}
* {{tlx|WinLossPct|0|5}} produces {{Font color|black|#dfdfdf|{{WinLossPct|0|5}}}}
* {{tlx|WinLossPct|0|0}} produces {{Font color|black|#dfdfdf|{{WinLossPct|0|0}}}}
* {{tlx|WinLossPct|0|0}} produces {{Font color|black|#dfdfdf|{{WinLossPct|0|0}}}}
* {{tlx|WinLossPct|5|3|2}} produces {{Font color|black|#dfdfdf|{{WinLossPct|5|3|2}}}}


<syntaxhighlight lang="wikitext">
<syntaxhighlight lang="wikitext">
Line 27: Line 32:
! Team !! Wins !! Losses !! Percent
! Team !! Wins !! Losses !! Percent
|-
|-
| Bluebirds || {{WinLossPct|6|9}}
| Bluebirds || {{WinLossPct|6|4}}
|-
|-
| Blackbirds || {{WinLossPct|4|3}}
| Blackbirds || {{WinLossPct|4|6}}
|}
|}

and

<syntaxhighlight lang="wikitext">
{| class=wikitable
! Team !! Wins !! Losses !! Ties !! Percent
|-
| Lemurs || {{WinLossPct|3|6|1}}
|-
| Ocelots || {{WinLossPct|6|3|1}}
|}
</syntaxhighlight>

produces:

{| class=wikitable
! Team !! Wins !! Losses !! Ties !! Percent
|-
| Lemurs || {{WinLossPct|3|6|1}}
|-
| Ocelots || {{WinLossPct|6|3|1}}
|}



==See also==
==See also==

Revision as of 17:40, 31 December 2023


Description

This template produces three or four wikitable columns that represent wins, losses, optionally ties, and a winning percentage as follows:

<wins> || <losses> || <winning percentage>

or

<wins> || <losses> || <ties> || <winning percentage>

where wins comes from parameter 1 to this template, losses comes from parameter 2, ties comes from parameter 3 if present, and <winning percentage> is automatically computed based on parameters 1 and 2 and 3 if present.[1]

Winning percentage is calculated as a three-decimal place value between .000 and 1.000. The value is wins / (wins + losses) for 2 parameters, or (wins + (ties / 2)) / (wins + losses + ties) for 3 parameters. If the total of the parameters is zero, the oercentage is "—".

Examples

{| class=wikitable
! Team !! Wins !! Losses !! Percent
|-
| Bluebirds  || {{WinLossPct|6|9}}
|-
| Blackbirds || {{WinLossPct|4|3}}
|}

produces:

Team Wins Losses Percent
Bluebirds 6 4 .600
Blackbirds 4 6 .400

and

{| class=wikitable
! Team !! Wins !! Losses !! Ties !! Percent
|-
| Lemurs  || {{WinLossPct|3|6|1}}
|-
| Ocelots || {{WinLossPct|6|3|1}}
|}

produces:

Team Wins Losses Ties Percent
Lemurs 3 6 1 .350
Ocelots 6 3 1 .650


See also

Notes

  1. ^ This is what is colloquially referred to as a "percentage" in sports, though it is not mathematically accurate. 6 wins and 6 losses produces ".500", not "50%".