Template:Convert/doc

From Teampedia
Jump to: navigation, search

Usage

This template can be used to show measurement quantities as primary and converted secondary units (or ranges), with optional rounding, wikilinks, abbreviation, or US spellings, and various separators including:  parentheses, slash, "or", hyphens, comma, "to" or dashes. Styles include: distance "32.0 metres (104.9868768 ft)" and "32.0 metres104.9868768 ft"; temperature "18 °C (64.4 °F)" or "18 °C/64.4 °F"; weight "55.0  (Expression error: Missing operand for *. )" or "65  (Expression error: Unexpected round operator. )"; etc. For units see: Convert/list of units.

Options include:  lk=in, abbr=on, sp=us, adj=on, disp=or, disp=table and sortable=on (explained below). By default, output is rounded to match the precision of input; alternatives include: sigfig=3 or using the end parameter, e.g. appending -2 to show full hundreds.

Single value:

{{convert|original_value|original_unit|conversion_unit|round_to|...}}

Range of values (see below for list of range options):

{{convert|orig_val1|range|orig_val2|original_unit|conversion_unit|round_to|...}}
  • Numbers must be entered in unformatted form (without commas). For negative numbers (i.e. temperatures or precision) use a hyphen as the minus sign for the input number. Values output by the template will be displayed formatted and with a true minus sign where appropriate. To specify with commas, re-code a number as {{formatnum:9,000,500|R}} (becomes 9000500).
  • Optional parameters, in examples below, allow abbreviated units (abbr=on), or US spellings (sp=us for meter), or slash separation (disp=s), or hyphenation (adj=on), etc.
  • For this template many levels of substitution are possible, hence doing this fully, step by step, is cumbersome, use Special:ExpandTemplates instead.
  • The template has no in-built capacity for dimensional analysis. It is therefore up to the user to ensure that the input and output units are compatible. Do not, for example, attempt to convert barrels to tonnes (but see {{bbl to t}}). Also beware of units with similar names; the code oz, for example, is for the avoirdupois ounce (a unit of mass), do not use this if you want fluid ounces.
  • An attempt to convert a unit to itself (e.g. km to km), will result in a template loop.
  • The range functionality is not fully implemented for all units, so experimentation may be required.
  • This documentation page tends to lag behind in terms of what the template can do. For details see the talk page and its archives.

Examples

Single value

Input Displays as
{{convert|3.21|kg|lb}} 3.21  (Expression error: Missing operand for *. )
{{convert|3.21|kg|lb|0}} 3.21  (Expression error: Unexpected round operator. )
{{convert|10|kg |lb |disp=or}} 10 Expression error: Missing operand for *. 
{{convert|6|ft|5|in|m}} 6 feet (Expression error: Unexpected round operator. )
{{convert|10|mi}} 10 miles (Expression error: Missing operand for *. )
{{convert|100|mpgus}} 100  (Expression error: Missing operand for *. )
{{convert|120|km/h}} 120 kilometres per hour (Expression error: Missing operand for *. )
{{convert|18|°C|°F}} 18 °C (64.4 °F)
{{convert|1250|sqft|m2|lk=in|sigfig=2}} 1,250  (Expression error: Missing operand for *. )
Note 'lk=in' links only the input unit. This example is for illustration only, common units of measurement should not be linked. See: wp:overlink.
{{convert|20.5|m3|cuyd|lk=out|abbr=on}} 20.5  (Expression error: Unexpected round operator. )
Note 'lk=out' links only the output unit, cu yd.
{{convert|641|acre|km2 sqmi|lk=on}} 641 acres (Expression error: Missing operand for *. [[]])
Note 'lk=on' links all units. Per guidelines, common units should not be linked. See: wp:overlink.
{{convert|641|acre|km2 sqmi|2|lk=on}} 641 acres (Expression error: Unexpected round operator. [[]])
Although 640 acres equals 1 square mile; 641 acres rounded to two decimal places equals 1.00 sq mi.

Range of values

Note: not yet operational for all units
Input Displays as
{{convert|60|and|170|kg|lb}} 60  (Expression error: Unexpected round operator. )
{{convert|60|to|170|kg|lb}} 60  (Expression error: Unexpected round operator. )
{{convert|60|to(-)|170|kg|lb}} 60  (Expression error: Unexpected round operator. )
{{convert|60|-|170|kg|lb}} 60  (Expression error: Unexpected round operator. )
{{convert|41|to|50|F|C}} 41  (Expression error: Unexpected round operator. )
{{convert|41|-|50 |F|K}} 41  (Expression error: Unexpected round operator. )
{{convert|60|by|120|m|ft}} 60  (Expression error: Unexpected round operator. )
{{convert|60|x|120|m|ft}} 60  (Expression error: Unexpected round operator. )
{{convert|60|+/-|10|m|ft}} 60  (Expression error: Unexpected round operator. )
{{convert|19|to|27|L|USgal}} 19  (Expression error: Unexpected round operator. )
{{convert|5|to|7|L|USgal|abbr=mos}} 5  (Expression error: Unexpected round operator. )
{{convert|4|-|9|L|USgal|abbr=none}} 4  (Expression error: Unexpected round operator. )

The following conversions are currently not available as a range of values:

  • Some imperial and US gallon-based units
  • Fuel consumption units (mpg, L/100km)
  • Large scale units (e3, e6, e9)
  • Combination-based units (ft&in, st&lb, lb&oz) due to complexity of the conversion

Parameters

Parameters
Template:AnchorUse US spelling attach |sp=us
Template:AnchorMake units wikilinked attach |lk=on   to link all unitsTemplate:In5(default: lk=off)
attach |lk=in   to link only the input units
attach |lk=out  to link only the output units
(The manual of style suggests that you should not link common units of measurement).
Template:AnchorUse the adjective form attach |adj=on (e.g. "The 190-foot (58 m) bridge" as opposed to "The 190 feet..."). This produces the adjective form—the unit name in the singular with a hyphen (according to the Manual of Style).
Template:AnchorAbbreviate units, or none attach |abbr=onTemplate:In5to show unit symbolsTemplate:In5(default: abbr=off)
attach |abbr=none   to show all units in full words
attach |abbr=in Template:In5 to abbreviate input units
attach |abbr=outTemplate:In5to abbreviate output units.
Change display option from "( )" attach |disp=commaTemplate:In5to put comma, not parentheses
attach |disp=orTemplate:In5to put "or" between units
attach |disp=s (or |disp=/) for slash (e.g. 190 foot/58 metre). The default value is:  disp=b for parentheses.
Display output only attach |disp=output only Template:In5 to show result number & unit
attach |disp=output number onlyTemplate:In5to show just number
Note when using "disp=output only" then the unit name can still be shown as full words by abbr=none, or linked by lk=on.
Display unit name (only) attach |disp=unit Template:In5 to show the unit name for a symbol
The unit name will be plural when the amount is not 1, or hyphenated when adj=on. So, {{convert|2|cuyd|disp=unit}} shows "cubic yards" plural.
Template:AnchorDisplay amounts as table cells attach |disp=table (or |disp=tablecen) Note: For use in tables, the template must start on a new line after a pipe. Only the number will be displayed unless you set |abbr=on, |lk=on, |lk=in or |lk=out. Example: here
Round to a specified number of significant figures attach |sigfig={some non-negative integer}. In the case of temperatures Celsius or Fahrenheit this refers to the difference with the absolute-zero temperature. For example, at room temperature two significant digits means rounded to tens of degrees.
Let Convert decide the unit to convert to skip the convert to parameter (which would otherwise be third unnamed parameter) e.g. {{convert|100|mi|0}} gives 100 miles (Expression error: Missing operand for *. ).
Display input value as a fraction
(still in prototype stage: limited functionality)
{{convert|3/8|in|mm|3|abbr=on}} 3/8 in (9.525 mm) or {{convert|11+1/4|in|cm|2|abbr=on}}11+1/4 in (11.64 cm)
Template:AnchorGenerate a hidden sort key for use with a sortable table attach |sortable=on to generate a hidden sort key (in the form of <span style="display:none">00000005</span>) so that sortable tables will sort correctly. This takes the first numeric value and left pads it with zeros to 16 places. It ignores any additional values, ie, if you use 6|ft|2|in as the value, it will only use the 6 for the sort key. This will cause numeric values to sort in numeric order, ie: 5, 10, 15 instead of 10, 15, 5.

Parameters still under construction

Parameters still under construction. May not work in all situations
disp=tablecen Similar to disp=table except that the values with be centered within the column. See the tables at La Nouvelle branch for in use examples.
disp=comma Similar to disp=s except the two values will be separated by a comma, for situations where the first value is already within parentheses. See the Geography tables on Labrador for an example.
abbr=in Abbreviates only the input unit.
abbr=out Abbreviates only the output unit.
abbr=comma Abbreviates (removes) commas. This is a limited, temporary option, until comma=off can be implemented. For ranges, using abbr=comma conflicts with internal options, so instead, append "nocomma" to a range-word: tonocomma, bynocomma, andnocomma, -nocomma & xnocomma.
abbr=mos For ranges, abbreviates as in WP:MOS, with the input unit repeated, twice.

Rounding

Convert supports four types of rounding:

Rounding to a given precision
Specify the desired precision with the fourth unnamed parameter or third unnamed parameter in the case where the convert to parameter is skipped (see above). The conversion is rounded off to the nearest power of 1/10 this number. For instance, if the result is 8621 and the round number is '-2', the result will be 8600. If the result is '234.0283043' and the round number is '0', the result will be 234.
Rounding to a given number of significant figures
Specify the desired number of significant figures using |sigfig={some non-negative integer} as noted above.
Combine both of the above
If both the desired precision and the desired number of significant figures are specified, the conversion will be rounded to the least precise of these.
Default rounding
If neither the desired precision nor the desired number of significant figures are specified, the conversion will be rounded either to a comparable precision as the input value (the number of digits after the decimal point—or the negative of the number of non-significant zeroes before the point—is increased by one if the conversion is a multiplication by a number between 0.02 and 0.2, remains the same if the factor is between 0.2 and 2, is decreased by 1 if it is between 2 and 20, and so on) or to two significant figures, whichever is the most precise. An exception to this is temperature wherein the conversion will be rounded either to precision comparable to that of the input value or to that which would give three significant figures when expressed in kelvins, whichever is the most precise.

Units supported

Template:Selfref The table below lists units supported by this template. It is divided up according to the quantity being measured. Not all supported units are listed here; there are links to complete lists for each quantity.

The codes listed in the code column (column 3) are accepted as input by the template. These can be used as the second or third unnamed parameter. For some units there exist alternative codes. These are listed in brackets and have been incorporated to make the code more flexible for editors, e.g. °F or F may be entered.

The codes listed in the combinations column (column 7) can be used to produce multiple conversions. They can only be used as the third unnamed parameter, e.g. {{convert|55|nmi|km mi}} produces "55 nautical miles (Expression error: Missing operand for *. )".

Template:Convert/list of units

Examples

See also

  • {{convinfobox}} for use in infoboxes
  • {{bbl to t}} for converting barrel of oil to tonnes
  • {{CwtQtrLb to kg}} for converting long hundred weights, quarters and pounds into kilograms
  • {{DMS2Deg}} for converting degrees, minutes and seconds to decimal degrees
  • {{HMS2Deg}} for converting hour angles, given in hours, minutes and seconds, to decimal degrees
  • Template:T1 for converting and displaying a person's height
  • {{miles-chains}} for converting miles and chains to kilometres linking "chains"
  • {{pop density}} for converting a population and area to a density
  • {{Inflation}} for calculating inflated prices
  • {{metricate}}