Template:Chance

From Terraria Mods Wiki
Jump to navigation Jump to search
Template-info.svg Documentation The documentation below is transcluded from Template:Chance/doc. (edit | history)

A standardized way of probability presentation.

Usage

{{ chance | <fraction> | <digit to round to> (optional) | pad = y/yes (optional) | reduce = n/no (optional) | mode = f/p (optional) }}

First unnamed parameter

The fraction of chance. e.g. 1/250, 4/100. It does not need to be an irreducible fraction, the template will reduce it if needed.

Second unnamed parameter

Rounds off the percent number to a multiple of 1/10 raised to a power, with the exponent equal to this number. Default value is 2.

pad

If set, when the actual number of digits is less than the given value specified by the second unnamed parameter, it will pad the percent number with zeros to that length.

reduce

Prevents automatic reduction of the fraction.

mode

If set to f, only output fractal part; if set to p, only output percent part.

Example

Code Result
{{chance|1/100}} 1*1/100 (1%)
{{chance|1 in 100}} 1*1/100 (1%)
{{chance|1 in 1,000}} 0.1*1/1000 (0.1%)
{{chance|1/2500}} 0.04*1/2500 (0.04%)
{{chance|1/100|pad=y}} 1.00*1/100 (1.00%)
{{chance|1/2500|4|pad=y}} 0.0400*1/2500 (0.0400%)
{{chance|1/7}} 14.29*1/7 (14.29%)
{{chance|1/7|4}} 14.2857*1/7 (14.2857%)
{{chance|84/1000}} 8.4*21/250 (8.4%)
{{chance|84/1000|reduce=n}} 8.4*84/1000 (8.4%)
{{chance|49/11250}} 0.44*49/11250 (0.44%)
{{chance|1/2500|mode=f}} 0.04*1/2500
{{chance|1/2500|mode=p}} 0.04*0.04%

Options

This template supports options through {{options}} template. All valid options are listed below, see {{options}} for usage and other infomation.

See Template:chance/initOptions for the initial options setting of this template.

NameAliasInitial ValueValue Mapping[1]Note
precisiondec
2As Unnamed parameter 2
pad(empty)yesy
ony
n(empty)
no(empty)
off(empty)
reduce(empty)y(empty)
yes(empty)
on(empty)
non
offn
modeboth
  1. Values with mapping will be stored and loaded as mapped value. Other values without mapping will be stored and loaded as-is.

Example:

A: {{chance|84/1000}}
{{options/set|chance|precision=4|pad=y|reduce=n}}
B: {{chance|84/1000}}
{{options/reset|chance}}

It will output:

A: 8.4*21/250 (8.4%)

B: 8.4000*84/1000 (8.4000%)