Template:Coppercost

From Wowpedia
Jump to: navigation, 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 0g.

Examples

Amount Coppercost
1234567 123g 45s 67c
123456 12g 34s 56c
3456 34s 56c
56 56c
200 2s
30000 3g
40056 4g 56c
0 0g
<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 }}
  1. Call the {{Cost}} template.
  2. Start the gold parameter. Only fill in if there is a valid amount parameter.
  3. Test if the amount is equal to zero or is big enough to get gold (100*100=10000 copper per gold).
  4. 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.
  5. Close the #ifexpr
  6. Close the #if
  7. Start the silver parameter. Only show if the amount of silver is more than zero.
  8. The expression calculates the amount (0-99) of silver coins. It is essentially is ( amount mod 10000) div 100.
  9. True clause of the #ifexpr. Fill in the silver amount. The expression is the same as the one on the previous line.
  10. Close the #ifexpr
  11. Start the copper parameter. Only show if the amount of copper is more than zero.
  12. The expression calculates the amount (0-99) of copper coins, amount mod 100.
  13. True clause of the #ifexpr. Fill in the copper amount. This is the same expression as on the previous line.
  14. Close the #ifexpr
  15. Close the Cost template