No edit summary |
m (Fixed typo.) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 61: | Line 61: | ||
-->{{#vardefine:gc|{{#expr:{{#var:gc}}+0}}}}<!-- |
-->{{#vardefine:gc|{{#expr:{{#var:gc}}+0}}}}<!-- |
||
-->{{#vardefine:sc|{{#expr:{{#var:sc}}+0}}}}<!-- |
-->{{#vardefine:sc|{{#expr:{{#var:sc}}+0}}}}<!-- |
||
− | -->{{#vardefine:cc|{{#expr:{{#var:cc}} |
+ | -->{{#vardefine:cc|{{#expr:{{#var:cc}}+0}}}}<!-- |
+ | |||
+ | //handle rounding |
||
+ | -->{{#vardefine:_value|{{#expr:{{#var:cc}}+{{#var:sc}}*100+{{#var:gc}}*10000+{{#var:pc}}*1000000 round {{{round|2}}}}}}}<!-- rounding |
||
+ | -->{{#vardefine:pc|{{#expr:floor({{#var:_value}}/1000000)}}}}<!-- retrieve new pc from rounded value |
||
+ | -->{{#vardefine:_value|{{#expr:{{#var:_value}}-{{#var:pc}}*1000000}}}}<!-- |
||
+ | -->{{#vardefine:gc|{{#expr:floor({{#var:_value}}/10000)}}}}<!-- retrieve new gc from rounded value |
||
+ | -->{{#vardefine:_value|{{#expr:{{#var:_value}}-{{#var:gc}}*10000}}}}<!-- |
||
+ | -->{{#vardefine:sc|{{#expr:floor({{#var:_value}}/100)}}}}<!-- retrieve new sc from rounded value |
||
+ | -->{{#vardefine:_value|{{#expr:{{#var:_value}}-{{#var:sc}}*100}}}}<!-- |
||
+ | -->{{#vardefine:cc|{{#expr:{{#var:_value}}/1}}|0}}<!-- retrieve new cc from rounded value |
||
+ | //fix potential rounding errors: |
||
+ | -->{{#if:{{#pos:{{#var:cc}}|.}}|<!-- |
||
+ | -->{{#vardefine:cc_len|{{#expr:{{#len:{{#sub:{{#var:cc}}|{{#pos:{{#var:cc}}|.}}}}}}-1}}}}<!-- length of decimal places |
||
+ | -->{{#ifexpr:{{#var:cc_len}}>{{{round|2}}} and {{{round|2}}}>=0|{{#vardefine:cc|{{#expr:{{#var:cc}} round {{{round|2}}}}}}}}}<!-- if cc_len exceeds planned rounding digits, round cc itself again |
||
+ | -->}}<!-- |
||
//render |
//render |
Revision as of 18:08, 10 November 2019
Documentation The documentation below is transcluded from Template:Coin/doc. (edit | history)
[purge]
This template is used as a standardized way to display formatted coin values.
Usage
There are 2 API styles:
Style A
{{ coin | <Platinum Coins> (optional) | <Gold Coins> (optional) | <Silver Coins> (optional) | <Copper Coins> }}
Example: {{ coin | 1 | 0 | 30 }}
means 1 Gold 30 Copper Coins.
Style B
{{ coin | <Platinum Coins>pc (optional) <Gold Coins>gc (optional) <Silver Coins>sc (optional) <Copper Coins>cc (optional) }}
Examples: {{ coin | 1gc30cc }}
means 1 Gold 30 Silver Coins; {{ coin | 1.25gc }}
means 1 Gold 25 Silver Coins.
Spacing and capitalization is ignored. The coins can be abbreviated with "p", "g", "s", and "c" (e.g. 1g30c).
Other parameters
- round
Digit to round the combined value to; default is 2. Can also be negative, and can be used with all API styles.
Examples
Code | Result |
---|---|
{{coin|30}} |
|
{{coin|1|30}} |
|
{{coin|1|1}} |
|
{{coin|1sc}} |
|
{{coin|10g}} |
Expression error: Unrecognized word "g".<span class="coins" data-info="Expression error: Unexpected < operator." title="Expression error: Unexpected < operator.Expression error: Unexpected < operator.Expression error: Unexpected < operator.Expression error: Unexpected < operator.Coins"> |
{{coin|10000cc}} |
|
{{coin|1000000}} |
|
{{coin|0}} |
|
{{coin|3|1|30}} |
|
{{coin|3|0|1|30}} |
|
{{coin|0|1|0|30}} |
|
{{coin|1.30gc}} |
|
{{coin|12 gc 80cc}} |
|
{{coin|12cc 80gc}} |
|
{{coin|130 SC}} |
|
{{coin|1.5gc130sc}} |
|
{{coin|1.0130gC}} |
|
{{coin|10130pc88gc66cc}} |
|
{{coin|32sc 57.8741cc}} |
|
{{coin|32sc 57.8741cc|round=3}} |
|
{{coin|32sc 57.8741cc|round=1}} |
|
{{coin|32sc 57.8741cc|round=0}} |
|
{{coin|32sc 57.8741cc|round=-1}} |
|
{{coin|32sc 54.9781cc|round=-1}} |
|
{{coin|32sc 57.8741cc|round=-2}} |
|
{{coin|14pc 56gc 32sc 57.8741cc|round=-6}} |
|
{{coin|14pc 56gc 32sc 57.8741cc|round=-7}} |
|
{{coin|14pc 56gc 32sc 57.8741cc|round=-8}} |
|
{{coin|54pc 56gc 32sc 57.8741cc|round=-8}} |
Note
- This template is table-sorting-friendly (needs
data-sort-type="number"
in header). See the example table above or here. - It is only designed for positive numbers – negative values as input may lead to unexpected results.
See also
- Template:pc: Platinum Coin .
- Template:gc: Gold Coin .
- Template:sc: Silver Coin .
- Template:cc: Copper Coin .
- Template:coin total: Totals coins.
- Template:dm: Defender Medal
10000*.