模板:Chance

来自Terraria Wiki
跳到导航 跳到搜索
This template is i18n-ready, which means it is easy to localize for different languages. Please see I18n & l10n for templates to learn more.
See Template:Chance/l10n for the localization of this template.
Template-info.svg 文档 以下文档来自Template:Chance/doc。(编辑 | 历史

This template provides a standardized way of presenting probabilities.

Usage

{{ chance | <fraction> | <digit to round to> (optional) | pad = y/yes (optional) | reduce = n/no (optional) | mode = f/p (optional) | comma = y/yes (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. Can also be in the format 1 in 250, 4 in 100 or 1:250, 4:100, but the first one is preferred.

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, the template will only display the fractal part. If set to p, it will only display the percentage part. By default, both are displayed.

comma

If set, then the numerator and denominator will be formatted with formatnum.

Example

Code Result
{{chance|1/100}} 1/100 (1%)
{{chance|1 in 100}} 1/100 (1%)
{{chance|1:100}} 1/100 (1%)
{{chance|1 in 1,000}} 1/1000 (0.1%)
{{chance|1/2500}} 1/2500 (0.04%)
{{chance|1/100|pad=y}} 1/100 (1.00%)
{{chance|1/2500|4|pad=y}} 1/2500 (0.0400%)
{{chance|1/7}} 1/7 (14.29%)
{{chance|1/7|4}} 1/7 (14.2857%)
{{chance|84/1000}} 21/250 (8.4%)
{{chance|84/1000|reduce=n}} 84/1000 (8.4%)
{{chance|49/11250}} 49/11250 (0.44%)
{{chance|1/2500|mode=f}} 1/2500
{{chance|1/2500|mode=p}} 0.04%
{{chance|1/2500|comma=y}} 1/2,500 (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
comma(empty)yesy
ony
n(empty)
no(empty)
off(empty)
  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: 21/250 (8.4%)

B: 84/1000 (8.4000%)