Template:Inflation

From Wikipedia, the free encyclopedia

This template employs intricate features of template syntax.
You are encouraged to familiarise yourself with its setup and parser functions before editing the template. If your edit causes unexpected problems, please undo it quickly, as this template may appear on a large number of pages.
Remember that you can conduct experiments, and should test all improvements, in either the general Template sandbox or your user space before changing anything here.
[edit] Template documentation

Contents

This template takes a country_code, for example, "US" for the United States or "UK" for United Kingdom, a value in that country's currency, a start_year, and applies to it the country's consumer price inflation until "recently".[1] This means that whenever a new year arrives, all articles using this template have their displayed values updated accordingly.

Alternatively, you can provide a second, optional end_year parameter, and the value will be inflated for the period between the two years, providing a convenient way of getting values from different time periods adjusted around the same date.

[edit] Usage

{{Inflation|country_code|value|start_year|r=digit}}
{{Inflation|country_code|value|start_year|end_year|r=digit}}

Where:

  • country_code and its minimum start_year can be any of the following:
Country name country_code start_year
Germany[2] DE 1951
United Kingdom[3] UK 1264
United States[4] US 1774
  • end_year, if provided, must be higher (later) than start_year, but not higher than the current year, and will default to "recently" if left out;
  • r=digit sets the digit in which the value must be rounded, defaulting to "0" if unspecified, i.e., without cents (see Tips & Tricks below for details on how to use this parameter).

Examples:

  • {{Inflation|DE|1000000|2000}} = 1136465
  • {{Inflation|US|1000000|2001|2001}} = 1.0E+6
  • {{Inflation|US|1000000|1990|2005|r=2}} = 1494145.25
  • {{Inflation|UK|1000000|1323|1978|r=-3}} = 68463000

Entering invalid parameters will result in a link to the NaN article:

  • {{Inflation}} = NaN
  • {{Inflation|abc}} = NaN
  • {{Inflation|DE|1000000}} = NaN
  • {{Inflation|US|1000000|1200|3000}} = NaN
  • {{Inflation|UK|1000000|2005|2004}} = NaN

[edit] Tips & Tricks

[edit] Rounding

By default the values are calculated to the unit, as for most huge values cents are undesirable. If you need a different precision you can provide the |r= parameter to determine in which digit the rounding must happen. To obtain cents you'd use |r=2, but other values can be used, including negative ones: |r=-3, for example, will round to the nearest thousand, |r=-6 to the nearest million, and so on and so forth.

[edit] Formatnum

For a better visualization you can format the returned value using either the internal {{formatnum:}} magic word, or the alternative {{Formatprice}} template (see below). Each method has its advantages and disadvantages.

{{formatnum:}} is the standard method for formatting numbers in MediaWiki. It add thousands and decimal separators according to the user settings, and works well for raw numbers composed of up to 15 digits and a dot. On the other hand, it doesn't allow one to set how many digits must be shown after the decimal dot. Thus, a calculated value of "1234.5" will appear as "1,234.5", not the expected "1,234.50", making it better suited for integer prices unless the value is known and you can add the missing zeros by hand:

  • DM {{formatnum:{{Inflation|DE|1000000|1957|1978}}}}.00 = DM 2,006,102.00
  • £{{formatnum:{{Inflation|UK|1000000|1323|1978|r=-4}}}} = £68,460,000
  • ${{formatnum:{{Inflation|US|1000000|1990|r=2}}}} = $1,586,364.72

Another potential source of difficulties resides in the way certain calculated values are expressed. In many cases the result comes as a number in engineering units ("1.2E+9" instead of "1200000000"), and when that happens {{formatnum:}}'ing the result fails. A workaround then is to express the value to be inflated with less digits, adding a multiplier text such as "million" after the result, and then hitting the "Show preview" button as many times as needed, changing parameters until the best result is found:

  • ${{formatnum:{{Inflation|US|1000000000|1900|r=-8}}}} = $2.55E+10
  • ${{formatnum:{{Inflation|US|1000000|1900|r=-5}}}} thousand = $2.55E+7 thousand
  • ${{formatnum:{{Inflation|US|1000|1900|r=-2}}}} million = $25,500 million
  • ${{formatnum:{{Inflation|US|1|1900|r=1}}}} billion = $25.5 billion

The following section provides an automated way of avoiding this trial and error scenario.

[edit] Formatprice

{{Formatprice}} is a template specifically designed to display price values, both big and small, in a more pleasant way than {{formatnum:}} allows for. For example, instead of showing the whole of a huge number such as "953,783,409,856.12", it would show it as "954 billion", while small numbers have their cents part appearing as expected, "1234.5" being properly shown as "1,234.50".

On the down side, {{Formatprice}} has no built-in intelligent handling of user locale settings, what means that some users might see a dot or a comma the opposite way they'd expect. As a general rule of thumb this shouldn't be a serious concern though, as most numbers in Wikipedia are hand-written anyway and will show as entered regardless of user settings.

  • DM {{Formatprice|{{Inflation|DE|1000000|1957|1978}}}} = DM 2.01 million
  • £{{Formatprice|{{Inflation|UK|1000000|1323|1978|r=-4}}}} = £68.5 million
  • ${{Formatprice|{{Inflation|US|1000000|1990|r=2}}}} = $1.59 million
  • ${{Formatprice|{{Inflation|US|1000000000|1900|r=-8}}}} = $25.5 billion
[edit] Documenting

It's a good practice to provide a valid reference for the prices calculated with this template in the articles where it's used. The template {{Inflation-fn}} was developed to ease this task. It accepts as its single parameter the same country codes used here, and will generate one or more appropriate footnotes. Typically, this is how a piece of text using it looks like:

  • In 1910 a ''blah'' cost on average £1,000. This is equivalent to £{{Formatprice|{{Inflation|UK|1000|1910|r=2}}}} in present day terms.{{Inflation-fn}}|UK}}

Resulting in this converted code (notice the footnote link at the end):

  • In 1910 a blah cost on average £1,000. This is equivalent to £73,154.78 in present day terms.[3]

The footnote thus generated appears whenever {{reflist}} or <references /> is used in an article, usually in its "References" section. See below for the live example in this document's own References section, or click the above generated footnote to jump to it.

[edit] Limitations

  1. Currently it isn't possible to "de-inflate" a value to what it would have been in a previous year. If you need this functionality, please request it at the talk page. Adding it won't be difficult, but there's no point in doing so before someone actually needs it.
  2. Substitution isn't supported at all. Trying to {{subst:Inflation|...}} would only result in a long sequence of embedded parser code without any direct benefit. If you need to obtain an inflated price only once, please use the special ExpandTemplates page then copy the result and paste it at the desired location.

[edit] References

  1. ^ How recently depends on how the data set for each countries is constructed, and on the internal tables being updated accordingly every January. Some data tables provide inflation data up to December 31, 2007, others up to roughly June-July 2007, and others yet up to December 31, 2006.
  2. ^ German inflation numbers based on data available from Deutsches Statistisches Bundesamt.
  3. ^ a b UK CPI inflation numbers based on data available from Measuring Worth: UK CPI.
  4. ^ US CPI inflation numbers based on data available from Measuring Worth: US CPI.

[edit] See also

Languages