Template:Coppercost
Jump to navigation
Jump to search
This template takes a money value as one parameter, representing the value in copper, and calls the {{Cost}} template to show the amount as gold, silver and copper.
Useful to represent amounts of money which are calculated, e.g. with the parserfunction #expr:.
The inverse of this template is {{costcopper}}, most commonly referenced using its {{sell}} alias.
Syntax
{{Coppercost|<amount>}}
amount is an amount of money, expressed as the number of copper coins. Gold, silver or copper coin numbers are only shown if they are not zero.
If amount is zero, the result is 0.
Examples
Amount | Coppercost |
---|---|
1234567 | 123 45 67 |
123456 | 12 34 56 |
3456 | 34 56 |
56 | 56 |
200 | 2 |
30000 | 3 |
40056 | 4 56 |
0 | 0 |
<empty> |
Source code explained
1 {{Cost 2 |g= {{ #if: {{{1|}}} 3 | {{ #ifexpr: {{{1}}}=0 or {{{1}}}>=10000 4 | {{ #expr: floor( {{{1|0}}} / 10000 ) }} 5 }} 6 }} 7 |s= {{ #ifexpr: 8 {{ #expr: floor( ({{{1|0}}} mod 10000) / 100 ) }} > 0 9 | {{ #expr: floor( ({{{1|0}}} mod 10000) /100) }} 10 }} 11 |c= {{ #ifexpr: 12 {{ #expr: ({{{1|0}}} mod 100) }} > 0 13 | {{ #expr: {{{1|0}}} mod 100) }} 14 }} 15 }}
- Call the {{Cost}} template.
- Start the gold parameter. Only fill in if there is a valid amount parameter.
- Test if the amount is equal to zero or is big enough to get gold (100*100=10000 copper per gold).
- If so, then put the value in: amount div 10000. Note: the div operator does not appear to do what it says on the tin, so we have to make do with a normal division rounded down.
- Close the #ifexpr
- Close the #if
- Start the silver parameter. Only show if the amount of silver is more than zero.
- The expression calculates the amount (0-99) of silver coins. It is essentially is ( amount mod 10000) div 100.
- True clause of the #ifexpr. Fill in the silver amount. The expression is the same as the one on the previous line.
- Close the #ifexpr
- Start the copper parameter. Only show if the amount of copper is more than zero.
- The expression calculates the amount (0-99) of copper coins, amount mod 100.
- True clause of the #ifexpr. Fill in the copper amount. This is the same expression as on the previous line.
- Close the #ifexpr
- Close the Cost template