Module:ProbabilityFormat/doc: Difference between revisions
Appearance
Created page with "{{documentation}} == Purpose == This module provides functions to convert fractional probabilities (e.g. `0.01`) into human-friendly text strings such as: * `"no chance"` * `"100% chance"` * `"about 1 in 100"` * `"almost zero chance (less than 1 in 1,000,000)"` It is designed for use in templates where probabilities need to be expressed in plain language. == Usage == Basic syntax: <syntaxhighlight lang="wikitext"> {{#invoke:ProbabilityFormat|convert|probability|cutof..." |
No edit summary |
||
Line 14: | Line 14: | ||
<syntaxhighlight lang="wikitext"> | <syntaxhighlight lang="wikitext"> | ||
{{#invoke:ProbabilityFormat|convert|probability|cutoff}} | <nowiki>{{#invoke:ProbabilityFormat|convert|probability|cutoff}}</nowiki> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 28: | Line 28: | ||
! Input !! Output | ! Input !! Output | ||
|- | |- | ||
| <code>{{#invoke:ProbabilityFormat|convert|0}}</code> || no chance | | <code><nowiki>{{#invoke:ProbabilityFormat|convert|0}}</nowiki></code> || no chance | ||
|- | |- | ||
| <code>{{#invoke:ProbabilityFormat|convert|1}}</code> || 100% chance | | <code>{{#invoke:ProbabilityFormat|convert|1}}</code> || 100% chance |
Revision as of 21:49, 2 September 2025
Purpose
This module provides functions to convert fractional probabilities (e.g. `0.01`) into human-friendly text strings such as:
- `"no chance"`
- `"100% chance"`
- `"about 1 in 100"`
- `"almost zero chance (less than 1 in 1,000,000)"`
It is designed for use in templates where probabilities need to be expressed in plain language.
Usage
Basic syntax:
<syntaxhighlight lang="wikitext"> {{#invoke:ProbabilityFormat|convert|probability|cutoff}} </syntaxhighlight>
probability
(required) — a number between `0` and `1`.cutoff
(optional) — probabilities smaller than this are treated as “almost zero chance.” Defaults to `1e-6` (1 in 1,000,000).
Parameters
probability
- The fractional probability, either as a number or string (e.g. `0.05`).
cutoff
- A fractional cutoff for “almost zero” reporting. For example, passing `1e-4` will show “less than 1 in 10,000.”
Examples
Input | Output |
---|---|
{{#invoke:ProbabilityFormat|convert|0}} |
no chance |
100% chance |
100% chance |
almost certain (more than 9 in 10) |
almost certain (more than 9 in 10) |
about 7 in 10 |
about 7 in 10 |
about 1 in 100 |
about 1 in 100 |
almost zero chance (less than 1 in 1,000,000) |
almost zero chance (less than 1 in 1,000,000) |
almost zero chance (less than 1 in 10,000) |
almost zero chance (less than 1 in 10,000) |