Difference between revisions of "Template:Convert/doc"

From Teampedia
Jump to: navigation, search
Line 1: Line 1:
{{documentation subpage}}
+
=== Usage ===
=== Units of measurement usage on Wikivoyage ===
+
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 "{{convert|32.0|m|ft}}" and "{{convert|32.0|m|ft|disp=or}}"; temperature "{{convert|18|°C|°F}}" or "{{convert|18|°C|°F|disp=s}}"; weight "{{convert|55.0|kg|lb|abbr=on}}" or "{{convert|65|to|80|kg|lb|abbr=on}}"; etc. For units see: [[Template:Convert/list of units|Convert/list of units]].
Format and conventions used for units can be found at [[Wikivoyage:Measurements]].
+
{|
 +
|- bgcolor="#FAFEFF" valign=top
 +
|Options&nbsp;include:&nbsp;||[[#lk_in|<code>lk=in</code>]], [[#abbr_on|<code>abbr=on</code>]], [[#sp_us|<code>sp=us</code>]], [[#adj_on|<code>adj=on</code>]], [[#disp_or|<code>disp=or</code>]], [[#disp_table|<code>disp=table</code>]] and [[#sortable_on|<code>sortable=on</code>]] (explained below). By default, output is [[#Rounding|rounded]] to match the precision of input; alternatives include: <code>sigfig=3</code> or using the end parameter, e.g. appending <code>-2</code> to show full hundreds.
 +
|}
 +
'''Single value''':
 +
<tt><nowiki>{{</nowiki>convert|''original_value''|''original_unit''|''conversion_unit''|''round_to''<nowiki>|...}}</nowiki></tt>
  
To ensure units are displayed correctly, the simplified individual template should be used.
+
'''Range of values''' (see below for list of ''range'' options):
 +
<tt><nowiki>{{</nowiki>convert|''orig_val1''|''range''|orig_val2|''original_unit''|''conversion_unit''|''round_to''<nowiki>|...}}</nowiki></tt>
  
The Convert template can be used in cases where standard format is not optimum.
+
* 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 <nowiki>{{formatnum:9,000,500|R}}</nowiki> (becomes 9000500).
==== Simplified unit of measurement templates ====
+
* 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.
*{{tl|km}} , {{tl|mi}}
+
* For this template many levels of [[Wikipedia:Template substitution|substitution]] are possible, hence doing this fully, step by step, is cumbersome, use [[Special:ExpandTemplates]] instead.
*{{tl|m}} , {{tl|ft}}, {{tl|yd}}
+
* 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 {{tl|bbl to t}}).  Also beware of units with similar names; the code <code>oz</code>, for example, is for the avoirdupois ounce (a unit of mass), do not use this if you want fluid ounces.
*{{tl|mm}} , {{tl|in}}
+
* An attempt to convert a unit to itself (e.g. km to km), will result in a template loop.
*{{tl|ha}} , {{tl|acre}}
+
* The range functionality is not fully implemented for all units, so experimentation may be required.
* {{tl|km2}} , {{tl|mi2}}
+
* This documentation page tends to lag behind in terms of what the template can do.  For details see the talk page and its archives.
* {{tl|m2}} , {{tl|ft2}}
+
* {{tl|kmh}} , {{tl|mph}}
+
* {{tl|kg}} , {{tl|lb}}
+
* {{tl|g}} , {{tl|oz}}
+
* {{tl|C}} , {{tl|F}}
+
  
=== Convert template usage ===
+
===Examples===
'''Template {{tl|convert}}''' ''calculates'' measurements from one unit (you can enter) to another one, and then ''presents the results''. For example:
+
====Single value====
:<code><nowiki>{{convert|2|km|mi}}</nowiki></code> → {{convert|2|km|mi}}
+
{| class="wikitable"
:<code><nowiki>{{convert|7|mi|km}}</nowiki></code> {{convert|7|mi|km}}<br />
+
|'''Input'''||'''Displays as'''
 
+
|-
Multiple '''formatting''' and calculation options are listed below.
+
|<nowiki>{{convert|3.21|kg|lb}}</nowiki>||{{convert|3.21|kg|lb}}
 
+
|-
==Unit name or symbol (abbreviation): ''1 pound'' or ''1 lb''?==
+
|<nowiki>{{convert|3.21|kg|lb|0}}</nowiki>||{{convert|3.21|kg|lb|0}}
By default, the first value shows unit name, the second the symbols (= abbreviation).
+
|-
Use {{para|abbr|on/off}} to change this behaviour:
+
|<nowiki>{{convert|10|kg |lb |disp=or}}</nowiki>||{{convert|10|kg |lb |disp=or}}
:<code><nowiki>{{lb to kg|1}}</nowiki></code> → {{convert|1|lb|kg}} (To compare; default: first value shows unit name)
+
|-
:<code><nowiki>{{lb to kg|1|abbr=on}}</nowiki></code> → {{lb to kg|1|abbr=on}}
+
|<nowiki>{{convert|6|ft|5|in|m}}</nowiki>||{{convert|6|ft|5|in|m}}
:<code><nowiki>{{convert|1|lb|kg|abbr=off}}</nowiki></code> {{convert|1|lb|kg|abbr=off}}
+
<!--This is currently broken, see talk page
* {{para|abbr|in}} toggles the default behaviour ({{para|abbr|out}}):
+
|-
:<code><nowiki>{{convert|1|lb|kg|abbr=in}}</nowiki></code> → {{convert|1|lb|kg|abbr=in}}
+
|<nowiki>{{convert|2|m|ftin}}</nowiki>||{{convert|2|m|ftin}}
 
+
-->
==Adjective: ''a 10-mile distance''==
+
|-
Use {{para|adj|on}} to produce the adjective form. The difference:
+
|<nowiki>{{convert|10|mi}}</nowiki>||{{convert|10|mi}}
:<code><nowiki>{{convert|10|mi|km}} to go</nowiki></code> → {{convert|10|mi|km}} to go. ''(To compare, default)''
+
|-
:<code><nowiki>A {{convert|10|mi|km|adj=on}} distance</nowiki></code> → A {{convert|10|mi|km|adj=on}} distance. ''(Adjective form)''
+
|<nowiki>{{convert|100|mpgus}}</nowiki>||{{convert|100|mpgus}}
 
+
|-
==Rounding: ''100 ft'' is ''30&nbsp;m'' or ''30.5&nbsp;m'' or ''30.48&nbsp;m''?==
+
|<nowiki>{{convert|120|km/h}}</nowiki>||{{convert|120|km/h}}
In detail, it is {{convert|100|ft|mm|sigfig=5|disp==}}. In practical use, it is common to round the calculated metric number. With that, there are several possibilities.
+
|-
 
+
|<nowiki>{{convert|18|°C|°F}}</nowiki>||{{convert|18|°C|°F}}
===Default rounding===
+
|-
:By default, the conversion result will be rounded either to precision comparable to that of 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 more precise. An exception to this is ''rounding temperatures'' (see [[#Rounding temperatures|below]]).
+
| <nowiki>{{convert|1250|sqft|m2|lk=in|sigfig=2}}</nowiki> ||{{convert|1250|sqft|m2|lk=in|sigfig=2}}<br/>Note 'lk=in' links only the input unit. This example is for illustration only, common units of measurement should not be linked. See: [[Wikipedia:Only make links that are relevant to the context|wp:overlink]].
 +
|-
 +
|<nowiki>{{convert|20.5|m3|cuyd|lk=out|abbr=on}}</nowiki>||{{convert|20.5|m3|cuyd|1|lk=out|abbr=on}}<br/>Note 'lk=out' links only the output unit, [[cu yd]].
 +
|-
 +
|<nowiki>{{convert|641|acre|km2 sqmi|lk=on}}</nowiki>||{{convert|641|acre|km2 sqmi|lk=on}}<br/>Note 'lk=on' links all units. Per guidelines, common units should not be linked. See: [[Wikipedia:Only make links that are relevant to the context|wp:overlink]].
 +
|-
 +
|<nowiki>{{convert|641|acre|km2 sqmi|2|lk=on}}</nowiki>||{{convert|641|acre|km2 sqmi|2|lk=on}}<br/> Although 640 acres equals 1 square mile; 641 acres rounded to two decimal places equals 1.00&nbsp;sq&nbsp;mi.
 +
|}
  
 +
====Range of values====
 +
:''Note: not yet operational for all units''
 
{| class="wikitable"
 
{| class="wikitable"
 +
|'''Input'''||'''Displays as'''
 
|-
 
|-
! colspan="3" | Examples of rounding
+
|<nowiki>{{convert|60|and|170|kg|lb}}</nowiki>||{{convert|60|and|170|kg|lb}}
 
|-
 
|-
|'''Input'''||'''Displays as'''||'''Note'''
+
|<nowiki>{{convert|60|to|170|kg|lb}}</nowiki>||{{convert|60|to|170|kg|lb}}
 
|-
 
|-
|<nowiki>{{convert|123|ft|m|-1}}</nowiki>||{{convert|123|ft|m|-1}} ||
+
|<nowiki>{{convert|60|to(-)|170|kg|lb}}</nowiki>||{{convert|60|to(-)|170|kg|lb}}
 
|-
 
|-
|<nowiki>{{convert|123|ft|m|0}}</nowiki>||{{convert|123|ft|m|0}} ||
+
|<nowiki>{{convert|60|-|170|kg|lb}}</nowiki>||{{convert|60|-|170|kg|lb}}
 
|-
 
|-
|<nowiki>{{convert|123|ft|m|1}}</nowiki>||{{convert|123|ft|m|1}} ||
+
|<nowiki>{{convert|41|to|50|F|C}}</nowiki>||{{convert|41|to|50|F|C}}
 
|-
 
|-
|<nowiki>{{convert|550|ft|m|0}}</nowiki>||{{convert|550|ft|m|0}} || Approximate value is 167.64 m
+
|<nowiki>{{convert|41|-|50 |F|K}}</nowiki>||{{convert|41|-|50 |F|K}}
 
|-
 
|-
|<nowiki>{{convert|550|ft|m}}</nowiki>||{{convert|550|ft|m}} || Rounds to 170, when approximate value is 167.64 m
+
|<nowiki>{{convert|60|by|120|m|ft}}</nowiki>||{{convert|60|by|120|m|ft}}
 
|-
 
|-
|<nowiki>{{convert|500|ft|m|0}}</nowiki>||{{convert|500|ft|m|0}} || Approximate value is 152.4 m
+
|<nowiki>{{convert|60|x|120|m|ft}}</nowiki>||{{convert|60|x|120|m|ft}}
 
|-
 
|-
|<nowiki>{{convert|500|ft|m}}</nowiki>||{{convert|500|ft|m}} || Rounds to 150, when approximate value is 152.4 m
+
|<nowiki>{{convert|60|+/-|10|m|ft}}</nowiki>||{{convert|60|+/-|10|m|ft}}
 +
|-
 +
|<nowiki>{{convert|19|to|27|L|USgal}}</nowiki>||{{convert|19|to|27|L|USgal}}
 +
|-
 +
|<nowiki>{{convert|5|to|7|L|USgal|abbr=mos}}</nowiki>||{{convert|5|to|7|L|USgal|abbr=mos}}
 +
|-
 +
|<nowiki>{{convert|4|-|9|L|USgal|abbr=none}}</nowiki>||{{convert|4|-|9|L|USgal|abbr=none}}
 
|}<!--NOTE: rows require "nowiki", using &#123;{ disappears. -->
 
|}<!--NOTE: rows require "nowiki", using &#123;{ disappears. -->
  
''Convert'' supports four types of rounding:
+
The following conversions are currently not available as a range of values:
 
+
*Some imperial and US gallon-based units
===Round to a given precision: ''use {{para|precision|}}''===
+
*Fuel consumption units (mpg, L/100km)<!-- except with <code>|abbr=on</code> no links and default <code>|disp=</code> -->
Specify the desired precision with the fourth unnamed parameter (or third unnamed parameter if the "convert to" parameter is omitted; or fifth unnamed parameter if a range is specified; or fourth unnamed parameter again if a range is specified and the "convert to" parameter is omitted; needs to be replaced with a "precision" named parameter). 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.
+
*Large scale units (e3, e6, e9)
 
+
*Combination-based units (ft&in, st&lb, lb&oz) due to complexity of the conversion
===Round to a given number of significant figures: ''use {{para|sigfig|}}''===
+
To specify the output number to be with ''n'' significant figures use {{para|sigfig|&lt;number>}}:
+
* <small>To compare:</small> <nowiki>{{convert|1200|ft|m}}</nowiki> → {{convert|1200|ft|m}}
+
* <nowiki>{{convert|1200|ft|m|sigfig=4}}</nowiki> → {{convert|1200|ft|m|sigfig=4}}
+
* <nowiki>{{convert|1200|ft|m|sigfig=3}}</nowiki> → {{convert|1200|ft|m|sigfig=3}}
+
* <nowiki>{{convert|1200|ft|m|sigfig=2}}</nowiki> → {{convert|1200|ft|m|sigfig=2}}
+
* <nowiki>{{convert|1200|ft|m|sigfig=1}}</nowiki> → {{convert|1200|ft|m|sigfig=1}}
+
Setting {{para|sigfig|&lt;=0}} is meaningless
+
* <nowiki>{{convert|1200|ft|m|sigfig=0}}</nowiki> → {{convert|1200|ft|m|sigfig=0}}
+
 
+
===Round to a multiple of 5: ''15'', ''20'', ''25'', ...===
+
Using {{para|round|5}} rounds the outcome to a multiple of 5.
+
:<code><nowiki>{{convert|10|m|ft}}</nowiki></code> → {{convert|10|m|ft}}
+
:<code><nowiki>{{convert|10|m|ft|round=5}}</nowiki></code> → {{convert|10|m|ft|round=5}}
+
 
+
Similar: using {{para|round|25}} rounds the outcome to a multiple of 25.
+
:<code><nowiki>{{convert|10|m|ft}}</nowiki></code> → {{convert|10|m|ft}}
+
:<code><nowiki>{{convert|10|m|ft|round=25}}</nowiki></code> → {{convert|10|m|ft|round=25}}
+
:<small>To compare:</small> <code><nowiki>{{convert|10|m|ft|sigfig=4}}</nowiki></code> → {{convert|10|m|ft|sigfig=4}}
+
 
+
In a range, one can round ''each value'' individually to the default. Use {{para|round|each}}:
+
:<code><nowiki>{{convert|10 x 200 x 3000|m|ft}}</nowiki></code> → {{convert|10 x 200 x 3000|m|ft}}
+
:<code><nowiki>{{convert|10 x 200 x 3000|m|ft|round=each}}</nowiki></code> → {{convert|10 x 200 x 3000|m|ft|round=each}}
+
 
+
===Round to a multiple of a given fraction: ''2 3/16 inch''===
+
Specify the desired ''denominator'' using {{para|frac|&lt;some positive integer&gt;}}. (Denominator is the below-the-slash number, for example the 3 in 1/3).
+
:<code><nowiki>{{convert|5.56|cm|in|frac=16}}</nowiki></code> → {{convert|5.56|cm|in|frac=16}}
+
:<code><nowiki>{{convert|8|cm|in|frac=4}}</nowiki></code> → {{convert|8|cm|in|frac=4}}
+
The fraction is reduced when possible:
+
:<code><nowiki>{{convert|8|cm|in|frac=100}}</nowiki></code> → {{convert|8|cm|in|frac=100}}
+
:<code><nowiki>{{convert|8|cm|in}}</nowiki></code> → {{convert|8|cm|in|sigfig=4}} (To compare)
+
 
+
==={{anchor|Rounding temperatures}}Rounding the temperatures °C, °F and K===
+
In temperatures, 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 more precise.
+
:<code><nowiki>{{convert|10|C|F K}}</nowiki></code> → {{convert|10|C|F K}}
+
''Note''
+
:For a temperature ''difference'', like to convert "A rise of 20 °C", use {{para|C-change|20}} &tc.
+
:<code><nowiki>{{convert|20|C-change|F-change K-change}}</nowiki></code> → A rise of {{convert|20|C-change|F-change K-change}}
+
 
+
:<small>To compare: "A temperature of 20 °C" would yield: A temperature of {{convert|20|C|F K}}</small>
+
 
+
==Into multiple units: ''{{convert|10|C|F K}}''==
+
Separate the multiple output units by a space:
+
:<code><nowiki>{{convert|10|C|F K}}</nowiki></code> → {{convert|10|C|F K}}
+
:<code><nowiki>{{convert|5|km|mi nmi}}</nowiki></code> → {{convert|5|km|mi nmi}}
+
 
+
==Ranges of values==
+
===A range: ''6 to 17 kg (13 to 37 lb)''===
+
Range indicators are entered as the second parameter (between the values). Range separators can be:<br />
+
{{Convert/doc/range separator list}}
+
 
+
===Multiple dimensions: ''{{convert|6|x|12|m|ft|abbr=on}}''===
+
; Use "by":
+
:<code><nowiki>{{convert|6|by|12|ft|m}}</nowiki></code> → {{convert|6|by|12|ft|m}}
+
;Use "×" or ""x"":
+
:<code><nowiki>{{convert|6|x|12|m|ft}}</nowiki></code> → {{convert|6|x|12|m|ft}}
+
 
+
In science, the formal way is to set <code>&#x7c;x&#x7c;</code> and {{para|abbr|on}} (keeping dimensions right, like in ''area = x km<sup>2</sup>''):
+
:<code><nowiki>{{convert|6|x|12|m|ft|abbr=on}}</nowiki></code> → {{convert|6|x|12|m|ft|abbr=on}}
+
 
+
===About ''feet, inch'' in ranges and multiples===
+
While it is possible to enter feet, inch in a simple conversion, this is not possible for ranges:
+
* <code><nowiki>{{convert|1|ft|3|in|mm}}</nowiki></code> → {{convert|1|ft|3|in|mm}} <small>(to compare)</small>
+
* <code><nowiki>{{convert|1|ft|3|in|x|3|ft|5|in|mm}}</nowiki></code> → {{convert|1|ft|3|in|x|3|ft|5|in|mm}}
+
 
+
==Words==
+
===Spelling of unit name: UK ''metre'' or US ''meter''?===
+
Default spelling of units is en-UK. To show en-US spelling, use {{para|sp|us}}:
+
:<code><nowiki>{{convert|1|m|ft}}</nowiki></code> → {{convert|1|m|ft}} -- ''default''
+
:<code><nowiki>{{convert|1|m|ft|sp=us}}</nowiki></code> → {{convert|1|m|ft|sp=us}}
+
 
+
===Spell out numbers: ''ten miles''===
+
To write a number in words, use {{para|spell|in}}:
+
:<code><nowiki>{{convert|10|mi|m|spell=in}}</nowiki></code> → {{convert|10|mi|m|spell=in}}
+
 
+
To make first letter a capital, use {{para|spell|In}}
+
:<code><nowiki>{{convert|10|mi|m|spell=In}}</nowiki></code> → {{convert|10|mi|m|spell=In}}
+
 
+
===Extra words: ''4 planted acres''===
+
:''Incomplete section''
+
:<code><nowiki>{{convert|4|acre||adj=pre|planted}}</nowiki></code> → {{convert|4|acre||adj=pre|planted}}
+
 
+
===Extra adjective words: ''A {{convert|10|ft|ft|adj=mid|-long|disp=out|order=flip}} corridor''===
+
:<code><nowiki>{{convert|4|ft|m|adj=mid|-long}}</nowiki></code> → {{convert|10|ft|m|adj=mid|-long}}
+
 
+
===Grammatical construction: ''The 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons''===
+
: "''The American defenders had 18-, 24- and 32-pounder (8,&nbsp;11&nbsp;and 15&nbsp;kg) cannons.''"
+
This formatted result is not possible straightforward by using {{tl|convert}}. However, it can be made in three steps.
+
:'''Step 1:''' Enter the input numbers and units in {{tl|convert}} just to get the calculated output:
+
:*<code><nowiki>had {{convert|18 |, |24 |, |32 |lb |kg |0 }} cannons</nowiki></code>
+
::→ had {{convert|18 |, |24 |, |32 |lb |kg |0 }} cannons
+
:The core conversion should look good now. You can save this (or preview).
+
:'''Step 2:''' We need the resulting text in plain code in the page, not as a {{tl|convert|...}} template.
+
:For this, '''add&nbsp;<code>subst:</code> to the template name''' (for 'substitute') :
+
:*<code><nowiki>had {{</nowiki>'''subst:'''<nowiki>convert|18 |, |24 |, |32 |lb |kg |0 }} cannons</nowiki></code>
+
:As a check: the preview result should show the conversion correct, with the numbers still right.
+
:'''Now save this'''.
+
::→ had 18,&nbsp;24,&nbsp;32 pounds (8,&nbsp;11,&nbsp;15&nbsp;kg) cannons
+
:'''Step 3:''' When opening the edit screen again, you'll see that the text is there in code. The template {{tl|convert|...}} itself has disappeared. You can change the text as needed. The edit screen text is:
+
::<code><nowiki>had 18,&amp;nbsp;24,&amp;nbsp;32 pounds (8,&amp;nbsp;11,&amp;nbsp;15&amp;nbsp;kg) cannons</nowiki></code>
+
:You can edit this text to add the grammar:
+
:*<code>had 18'''-''','''_'''24'''-_and_'''32'''-'''pound'''er''' (8,&amp;nbsp;11'''_and_'''15&amp;nbsp;kg) cannons </code>
+
:After saving your edit, it shows:
+
::→ "had 18-, 24- and 32-pounder (8,&nbsp;11&nbsp;and 15&nbsp;kg) cannons".
+
 
+
==Numbers==
+
===Using an SI prefix: ''gigameter (Gm)'', or ''micrometer (μm)''===
+
Units can have an SI prefix like <code>G</code> before the unit: <code>Gm</code>, and <code>giga</code> before the name: <code>gigameter</code>. These are plain multiplication factors.
+
 
+
To illustrate, these are trivial calculations (from meter to meter), showing the multiplication factor:
+
* {{convert|12|Gm|m|abbr=on}}
+
* {{convert|12|μm|m|abbr=on}}
+
 
+
The prefix can be added before the SI unit (here: unit <code>m</code> for meter):
+
* <code><nowiki>{{convert|12|Gm|mi|abbr=on}}</nowiki></code> → {{convert|12|Gm|mi|abbr=on}}
+
* <code>Mm</code>: {{convert|12|Mm|mi|abbr=on}}
+
* <code>km</code>: {{convert|12|km|ft|abbr=on}}
+
* <code>mm</code>: {{convert|12|mm|in|abbr=on}}
+
* <code>μm</code>: {{convert|12|μm|mm|abbr=on}}
+
* <code>um</code>: {{convert|12|um|mm|abbr=on}} (letter "u" can be used for "μ" here)
+
 
+
The prefix can be used in the output unit:
+
* <code><nowiki>{{convert|12000|mi||Mm|abbr=on}}</nowiki></code> → {{convert|12000|mi|Mm|abbr=on}}
+
* <code><nowiki>{{convert|12|in|μm|abbr=on}}</nowiki></code> → {{convert|12|in|μm|abbr=on}}
+
 
+
As an exception, the non-SI unit "inch" can have the "μ" prefix  too)
+
* <code><nowiki>{{convert|12|μm|μin|abbr=on}}</nowiki></code> → {{convert|12|μm|μin|abbr=on}}
+
 
+
===Thousands separator: ''1,000 mi'' and ''1000 mi''===
+
In input, a comma for thousands separator is accepted. A gap (space) is not. In output, by default, the thousand separator is the comma:
+
*<code><nowiki>{{convert|1,234,567|m|ft}}</nowiki></code> → {{convert|1,234,567|m|ft}}
+
*<code><nowiki>{{convert|1,234,567|m|ft}}</nowiki></code> → {{convert|1,234,567|m|ft}}
+
*<s><code><nowiki>{{convert|1 234 567|m|ft}}</nowiki></code> → {{convert|1 234 567|m|ft}}</s>
+
 
+
Set {{para|comma|off}} to remove the separator:
+
*<code><nowiki>{{convert|1234567|m|ft|comma=off}}</nowiki></code> → {{convert|1234567|m|ft|adj=nocomma}}
+
 
+
Use {{para|comma|gaps}} to set digit grouping by gap (<code>&lt;space></code>) in larger numbers (thousands separator):
+
*<code><nowiki>{{convert|1234567|m|ft}}</nowiki></code> → {{convert|1234567|m|ft}} <small>(To compare, default)</small>
+
*<code><nowiki>{{convert|1234567|m|ft|comma=gaps}}</nowiki></code> → {{convert|1234567|m|ft|comma=gaps}}
+
 
+
Setting {{para|comma|5}} or {{para|comma|gaps5}} will only add the separator when the number of digits is 5 or more:
+
*<code><nowiki>{{convert|1234|m|ft}}</nowiki></code> → {{convert|1234|m|ft}} (To compare, default)
+
*<code><nowiki>{{convert|1234|m|ft|comma=5}}</nowiki></code> → {{convert|1234|m|ft|comma=5}}
+
*<code><nowiki>{{convert|1234567|m|ft|comma=5}}</nowiki></code> → {{convert|1234567|m|ft|comma=5}}
+
*<code><nowiki>{{convert|1234|m|ft|comma=gaps5}}</nowiki></code> → {{convert|1234|m|ft|comma=gaps5}}
+
*<code><nowiki>{{convert|1234567|m|ft|comma=gaps5}}</nowiki></code> → {{convert|1234567|m|ft|comma=gaps5}}
+
 
+
==Output manipulation==
+
===Brackets and separators: ''10 m [33 ft]''===
+
Punctuation that distinguishes the two measurements is set by {{para|disp|}}.<br />
+
Options are: <code>b</code> <small>(the default)</small>, <code>sqbr</code>, <code>comma</code>, <code>or</code>, <code>br</code>, <code>x{{!}}...</code>:
+
:<code><nowiki>{{convert|10|m|ft}}</nowiki></code> → {{convert|10|m|ft}} -- ''(&nbsp;) brackets are the default''
+
:<code><nowiki>{{convert|10|m|ft|disp=sqbr}}</nowiki></code> → {{convert|10|m|ft|disp=sqbr}}
+
:<code><nowiki>{{convert|10|m|ft|disp=comma}}</nowiki></code> → {{convert|10|m|ft|disp=comma}}
+
:<code><nowiki>{{convert|10|m|ft|disp=or}}</nowiki></code> → {{convert|10|m|ft|disp=or}}
+
 
+
Setting {{para|disp|br}} will force a new line (<code>&lt;br></code>)
+
 
+
:<code><nowiki>{{convert|10|m|ft|disp=br}}</nowiki></code> → {{convert|10|m|ft|disp=br}}
+
Setting {{para|disp|x{{!}}...}} allows any text as separator:
+
 
+
:<code><nowiki>{{convert|10|m|ft|disp=x|_MyText_}}</nowiki></code> → {{convert|10|m|ft|disp=x|_MyText_}} -- <small>(To display spaces, use <code>&amp;nbsp;</code>)</small>
+
 
+
===Flipping (reordering) the two measurements: ''{{convert|1|mi|m|order=flip|sigfig=5|abbr=off}}'' ===
+
Setting {{para|order|flip}} will flip (swap) the two measurements:
+
:<code><nowiki>{{convert|1|mi|m}}</nowiki></code> → {{convert|1|mi|m|sigfig=5|abbr=off}} <small>(To compare, default)</small>
+
:<code><nowiki>{{convert|1|mi|m|order=flip}}</nowiki></code> → {{convert|1|mi|m|order=flip|sigfig=5|abbr=off}}<!-- Extra settings added to enhance the illustration. Don't know if this is ideal way of documenting. DePiep, August 2014. -->
+
 
+
When converting to multiple units, the effect is:
+
:<code><nowiki>{{convert|10|km|mi nmi|order=flip}}</nowiki></code> → {{convert|10|km|mi nmi|order=flip|sigfig=5|abbr=off}}
+
:<code><nowiki>{{convert|10|km|nmi mi|order=flip}}</nowiki></code> → {{convert|10|km|nmi mi|order=flip|sigfig=5|abbr=off}}
+
 
+
=== Displaying parts of the result: ''{{convert|2|cuyd|m3|abbr=values}}''===
+
It is possible to display only parts of the conversion result:
+
<!-- todo: describe effect of order=flip ("out" means 1st or 2nd measurement?) -->
+
  
 +
===Parameters===
 
{| class="wikitable"
 
{| class="wikitable"
! Convert !! Output !! Description
 
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3}}</nowiki></code> || {{convert|2|cuyd|m3}} || Default, to compare
+
! colspan="2" | Parameters
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|abbr=values}}</nowiki></code> || {{convert|2|cuyd|m3|abbr=values}} || Input and output numbers
+
| {{anchor|sp_us}}Use [[United States|US]] spelling || attach <code><nowiki>|sp=us</nowiki></code>
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit}} || Input unit
+
| {{anchor|lk_in}}Make units [[Wikipedia:Manual of Style (links)|wikilinked]] || attach <code><nowiki>|lk=on</nowiki></code> &nbsp; to link all units{{in5|31}}(default: <tt>lk=off</tt>)<br> attach <code><nowiki>|lk=in</nowiki></code> &nbsp; to link only the input units<br> attach <code><nowiki>|lk=out</nowiki></code>&nbsp; to link only the output units<br>(The [[Wikipedia:Only make links that are relevant to the context|manual of style]] suggests that you should not link common units of measurement).
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit|adj=on}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit|adj=on}} || Input unit, adjective (hyphenated)
+
| {{anchor|adj_on}}Use the adjective form || attach <code><nowiki>|adj=on</nowiki></code> (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 [[WP:HYPHEN|Manual of Style]]).
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|cuyd|0|disp=out|abbr=off}}</nowiki></code> || {{convert|2|cuyd|cuyd|0|disp=out|abbr=off}} || Input (''workaround'')
+
| {{anchor|abbr_on}}Abbreviate units, or none || attach <code><nowiki>|abbr=on</nowiki></code>{{in5|7}}to show unit symbols{{in5|10}}(default: <tt>abbr=off</tt>)<br> attach <code><nowiki>|abbr=none</nowiki></code> &nbsp; to show all units in full words<br> attach <code><nowiki>|abbr=in</nowiki></code> {{in5}} to abbreviate input units<br> attach <code><nowiki>|abbr=out</nowiki></code>{{in5}}to abbreviate output units.
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit2}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit2}} || Output unit (symbol)
+
| Change display option from "( )" || attach <code>&#124;disp=comma</code>{{in5|4}}to put comma, not parentheses<br> attach <code>&#124;disp=or</code>{{in5|10}}to put "or" between units<br> attach <code>&#124;disp=s</code> (or  <code><nowiki>|disp=/</nowiki></code>) for slash (e.g. 190&nbsp;foot/58&nbsp;metre). The default value is:&nbsp; disp=b for parentheses.
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit2|abbr=off}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit2|abbr=off}} || Output unit (name)
+
| Display output only || attach <code>&#124;disp=output only</code> {{in5|15}} to show result number & unit<br> attach <code>&#124;disp=output number only</code>{{in5|3}}to show just number<br>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.
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=number}}</nowiki></code> || {{convert|2|cuyd|m3|disp=number}} || Output value
+
| Display unit name (only) || attach <code>&#124;disp=unit</code> {{in5|7}} to show the unit name for a symbol<br>The unit name will be plural when the amount is not 1, or hyphenated when adj=on. So, <nowiki>{{convert|2|cuyd|disp=unit}}</nowiki> shows "cubic yards" plural.
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=out}}</nowiki></code> || {{convert|2|cuyd|m3|disp=out}} || Output value and unit
+
| {{anchor|disp_table}}Display amounts as table cells || attach <tt>&#124;disp=table</tt> (or <tt>&#124;disp=tablecen</tt>) 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 <code><nowiki>|abbr=on</nowiki></code>, <code><nowiki>|lk=on</nowiki></code>, <code><nowiki>|lk=in</nowiki></code> or <code><nowiki>|lk=out</nowiki></code>. Example: [[Phnom_Penh#Highways_in_Phnom_Penh|here]]
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=out|abbr=off}}</nowiki></code> || {{convert|2|cuyd|m3|disp=ou|abbr=offt}} || Output value and unit
+
| Round to a specified number of significant figures|| attach <code><nowiki>|sigfig={some non-negative integer}</nowiki></code>. 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.
|}
+
 
+
==Table options==
+
For the wikitable structure, there are two options: split over columns and make the table sortable.
+
===Show numbers only in columns in a table===
+
Using {convert} in a table cell, with {{para|disp|table}} splits the result over two columns:
+
:<code><nowiki>{{convert|10|m|ft|disp=table}}</nowiki></code> → {{convert|10|m|ft|disp=table}}
+
 
+
{{para|disp|tablecen}} does the same, and also centers the text:
+
:<code><nowiki>{{convert|20|m|ft|disp=tablecen}}</nowiki></code> → {{convert|20|m|ft|disp=tablecen}}
+
 
+
The units are added as a column header:
+
:{| class=wikitable
+
! style="width:10em;" | &nbsp;
+
! style="width:10em;" | m
+
! style="width:10em;" | ft
+
 
|-
 
|-
| {{para|disp|table}}
+
| Let ''Convert'' decide the unit to convert to|| skip the ''convert to'' parameter (which would otherwise be third unnamed parameter) e.g. <code><nowiki>{{convert|100|mi|0}}</nowiki></code> gives ''{{convert|100|mi|0}}''.
| {{convert|10|m|ft|disp=table}}
+
 
|-
 
|-
|{{para|disp|tablecen}}
+
|Display input value as a fraction<br/>(still in prototype stage: limited functionality)|| <nowiki>{{convert|3/8|in|mm|3|abbr=on}}</nowiki><font color=blue>'''→'''</font> {{convert|3/8|in|mm|3|abbr=on}} or <nowiki>{{convert|11+1/4|in|cm|2|abbr=on}}</nowiki><font color=blue>'''→'''</font>{{convert|11+1/4|in|cm|2|abbr=on}}
| {{convert|20|m|ft|disp=tablecen}}
+
 
|-
 
|-
|{{para|disp|&lt;other>}} <small>(default)</small>
+
|{{anchor|sortable_on}}Generate a [[Help:Sorting#Sorting with hidden sortkey|hidden sort key]] for use with a [[Help:Sorting|sortable table]]|| attach <code><nowiki>|sortable=on</nowiki></code> to generate a [[Help:Sorting#Sorting with hidden sortkey|hidden sort key]] (in the form of <code><nowiki><span style="display:none">00000005</span></nowiki></code>) so that [[Help:Sorting|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 <code>6|ft|2|in</code> 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.
|{{convert|30|m|ft|disp=}}
+
 
|}
 
|}
  
===Sorting===
+
====Parameters still under construction====
:Use both {{para|disp|table}} {{para|sortable|on}} to produce table columns (pipe symbols), with sortable table column. As of January 2013, only the first (lefthand) column will sort (improvements pending).
+
{| class="wikitable"
 
+
|-
:<nowiki>{{convert|10|m|ft|disp=table|sortable=on}}</nowiki> →
+
! colspan="2" | Parameters still under construction.  May not work in all situations
<code>{{nowrap|{{convert|10|m|ft|disp=table|sortable=on}}}}</code>
+
:This shows the hidden numerical sortkey:
+
<code>align="right"|&lt;span style="display:none">7001100000000000000&lt;/span>10 |align="right"|33</code>
+
 
+
:{| class="wikitable sortable"
+
! m
+
! ft
+
 
|-
 
|-
| {{convert|15+3/4|m|ft|disp=table|sortable=on}}
+
|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.
 
|-
 
|-
| {{convert|15.5|m|ft|disp=table|sortable=on}}
+
|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.
 
|-
 
|-
| {{convert|16.0|m|ft|disp=table|sortable=on}}
+
|abbr=in||Abbreviates only the input unit.
 
|-
 
|-
| {{convert|16|m|ft|disp=table|sortable=on}}
+
|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.
 
|}
 
|}
  
==Parameter list==
+
===Rounding===
{{convert/doc/parameter list}}
+
''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 <code><nowiki>|sigfig={some non-negative integer}</nowiki></code> 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 ===
 +
 
 +
{{selfref|See also: [[Template:Convert/list of units|Convert/list of units]]}}
 +
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. <code><nowiki>{{convert|55|nmi|km mi}}</nowiki></code> produces "{{convert|55|nmi|km mi}}".
 +
 
 +
<div style="height: 400px; overflow: auto; padding: 3px; border: 1px solid #aaa;">
 +
{{Convert/list of units}}
 +
</div>
 +
 
 +
===Examples===
 +
* Monitor quality or look at examples at {{tl|Convert/check}}.
 +
 
 +
===See also===
 +
* {{tl|convinfobox}} for use in infoboxes
 +
* {{tl|bbl to t}} for converting barrel of oil to tonnes
 +
* {{tl|CwtQtrLb to kg}} for converting long hundred weights, quarters and pounds into kilograms
 +
* {{tl|DMS2Deg}} for converting degrees, minutes and seconds to decimal degrees
 +
* {{tl|HMS2Deg}} for converting [[hour angle]]s, given in hours, minutes and seconds, to decimal degrees
 +
* {{t1|height}} for converting and displaying a person's height
 +
* {{tl|miles-chains}} for converting miles and chains to kilometres linking "chains"
 +
* {{tl|pop density}} for converting a population and area to a density
 +
* {{tl|Inflation}} for calculating inflated prices
 +
* {{tl|metricate}}
  
 
<includeonly>
 
<includeonly>
[[Category:Formatting and function templates‎]]
+
{{pp-template}}
 +
<!-- ADD CATEGORIES BELOW THIS LINE -->
 +
[[Category:Conversion templates| ]]
 +
 
 +
<!-- ADD INTERWIKIS BELOW THIS LINE -->
 +
[[es:Plantilla:Convert]]
 +
[[bn:template:Convert]]
 +
[[fr:Modèle:Conversion]]
 +
[[id:Templat:Convert]]
 +
[[it:Template:Converti]]
 +
[[ja:Template:Convert]]
 +
[[no:Mal:Convert]]
 +
[[pt:Predefinição:Convert]]
 +
[[th:แม่แบบ:Convert]]
 +
[[zh:Template:Convert]]
 
</includeonly>
 
</includeonly>

Revision as of 15:09, 11 April 2020

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}}