scratchpad

The {{convert}} template is used to convert a value from one unit of measurement to another. This page provides an overview of the options available when using the template.

Asking questions

Units

Quick start

By default, the name of the input unit is shown, while the output is abbreviated using the unit's symbol. If wanted, names or symbols can be used, and the output precision can be specified.

To avoid overlinking, units are not normally linked, but they can be when needed.

A convert can be used in an adjectival phrase, and user-specified text can be inserted.

If no output unit is specified, a default is used.

The last example used || to explicitly show that the output unit has been omitted. If that is not done, the result is an error, and holding the mouse over the error message shows that "-long" is misinterpreted as the output unit.

The input and outputs can be "flipped". When flipped, an option such as |lk=out means "link the right-hand side".

The input value can be spelled.

Ranges of values are supported.

A range can use more than two values.

Some input units consist of multiple components.

An output can be a combination of several units.

Some outputs consist of multiple units.

Rounding

By default, the output value is rounded to adjust its precision to match that of the input. An input such as 1234 is interpreted as 1234 ± 0.5, while 1200 is interpreted as 1200 ± 50, and the output value is displayed accordingly, taking into account the scale factor used in the conversion.

If the default is not wanted, the precision of output values can be specified using:

Examples:

An input value such as 5000 is assumed to have one significant figure, while 5001 has four. If wanted, "5000." can be used to specify an input number that has four significant figures.

Spell

Use US (en-US) spelling for unit names

Use |sp=us to specify that unit names should be displayed with US spelling:

Spell out numbers in words

Use |spell=in to specify that the input value should be spelled in words, or |spell=In (uppercase "I") to start with an uppercase letter:

The input and output can be "flipped", as shown in these examples. Logically, the resulting first number is spelled:

The "||" provides an empty output unit to mean "use the default".

Both input and output values can be spelled:

Thousands separator

Commas in input numbers are ignored. Gaps are not allowed in input.

In output, by default, the thousands separator is the comma:

Set |comma=off to remove separators from the result:

Setting |comma=5 adds a separator only when the number of digits is 5 or more:

Set |comma=gaps to use a small space for thousands grouping. If the resulting number is copied, only the digits are copied (the gaps are omitted).

Gaps are inserted on both sides of the decimal mark. However, by default, no gap is inserted before a single digit. If a gap is always wanted, |comma=gaps3 can be used.

Fractions

An input value can be specified as a fraction.

If two slashes are used, a horizontal fraction bar is used.

An output can be expressed with a fraction using |frac=N where N is the denominator. For example, |frac=8 rounds the output to the nearest eighth.

A fraction is applied to the output unit (if there is only one), or to non-SI units (if using a combination), except that if a precision is also specified, the fraction only applies to the hand unit.

Joins

The |disp= ("display") option may be used to "join" the input and output, as shown in the following examples.

Convert Output Description
{{convert|2.4|m|ft}} 2.4 metres (7.9 ft) default
{{convert|2.4|m|ft|disp=b}} 2.4 metres (7.9 ft) brackets (same as default)
{{convert|2.4|m|ft|disp=sqbr}} 2.4 metres [7.9 ft] square brackets
{{convert|2.4|m|ft|disp=or}} 2.4 metres or 7.9 feet or
{{convert|2.4|m|ft|disp=comma}} 2.4 metres, 7.9 ft comma
{{convert|2.4|m|ft|disp=br}} 2.4 metres
7.9 feet
"<br />", line break

Ranges

A range of values can be specified, as shown in the following examples.

Separator Convert Result Notes
- {{convert|3|-|6|ft}} 3–6 feet (0.91–1.83 m) Input can be hyphen (-) or en dash (–), output uses en dash
and {{convert|3|and|6|ft}} 3 and 6 feet (0.91 and 1.83 m)
and(-) {{convert|3|and(-)|6|ft}} 3 and 6 feet (0.91–1.83 m) and on left; en dash on right
and(-)|order=flip {{convert|3|and(-)|6|ft|order=flip}} 0.91 and 1.83 metres (3–6 ft)
or {{convert|3|or|6|ft}} 3 or 6 feet (0.91 or 1.83 m)
to {{convert|3|to|6|ft}} 3 to 6 feet (0.91 to 1.83 m)
to(-) {{convert|3|to(-)|6|ft}} 3 to 6 feet (0.91–1.83 m) to on left; en dash on right
to(-)|order=flip {{convert|3|to(-)|6|ft|order=flip}} 0.91 to 1.83 metres (3–6 ft)
to about {{convert|3|to about|6|ft}} 3 to about 6 feet (0.91 to about 1.83 m)
+/- {{convert|3|+/-|6|ft}} 3 ± 6 feet (0.91 ± 1.83 m)
Template:Hidden sort key± &plusmn; {{convert|3|±|6|ft}} 3 ± 6 feet (0.91 ± 1.83 m)
+ {{convert|3|+|6|ft}} 3 + 6 feet (0.91 + 1.83 m)
, {{convert|3|,|6|ft}} 3, 6 feet (0.91, 1.83 m)
, and {{convert|3|, and|6|ft}} 3, and 6 feet (0.91, and 1.83 m)
, or {{convert|3|, or|6|ft}} 3, or 6 feet (0.91, or 1.83 m)
by {{convert|3|by|6|ft}} 3 by 6 feet (0.91 by 1.83 m)
by(x) {{convert|3|by(x)|6|ft}} 3 by 6 feet (0.91 m × 1.83 m) by on left; multiply (×) on right
by(x)|order=flip {{convert|3|by(x)|6|ft|order=flip}} 0.91 by 1.83 metres (3 ft × 6 ft)
x {{convert|3|x|6|ft}} 3 by 6 feet (0.91 m × 1.83 m) Scientific notation.
|abbr=on alters the punctuation
x|abbr=on {{convert|3|x|6|ft|abbr=on}} 3 ft × 6 ft (0.91 m × 1.83 m)
xx |xx| is deprecated. Use |x| instead
* |*| is deprecated. Use |x| instead
to- |to-| is deprecated. Use |to(-)| instead
& |&| is deprecated. Use |and| instead
abbr=mos |abbr=mos is deprecated. Use |x| or |by| instead

Ranges can use more than two values.

Convert Output
{{convert|3|x|4|x|24|in}} 3 by 4 by 24 inches (76 mm × 102 mm × 610 mm)
{{convert|3|x|4|to|6+1/2|x|8+3/4|in}} 3 by 4 to 6 12 by 8 34 inches (76 mm × 102 mm to 165 mm × 222 mm)

Ranges can be specified in the first parameter.

Convert Output
{{convert|3.2-7.5|ha}} 3.2–7.5 hectares (7.9–18.5 acres)
{{convert|3x4x24|in}} 3 by 4 by 24 inches (76 mm × 102 mm × 610 mm)

Extra words

Some options provide text that is included in the output, as shown in the following examples.

Convert Output Description
{{convert|4|ft||adj=mid|-long}} 4-foot-long (1.2 m) Adjectival with mid-text between input and output (sets |adj=on)
{{convert|40|acre||adj=pre|planted}} 40 planted acres (16 ha) Text before the input unit
{{convert|4|m||disp=preunit|+ }} 4+ metres (13+ ft) Same text before the input and output units
{{convert|4|m||disp=preunit|+ |or more }} 4+ metres (13 or more ft) Different text before the input and output units
{{convert|20|impfloz||disp=x|, approximately }} 20 imperial fluid ounces, approximately 570 ml; 19 US fl oz Text before the output (replaces the join)
{{convert|100|m||disp=x|/day (|/day)}} 100 metres/day (330 ft/day) Text before and after the output (replaces the join)

In each of the above examples, "||" provides an empty output unit which causes the default output to be used. An output unit, possibly empty, must be specified to avoid the template interpreting the extra text as the output unit. For example, using {{convert|4|ft|adj=mid|-long}} has the same effect as using {{convert|4|ft|-long|adj=mid}}, namely that an error would occur because "-long" would be used as the output unit. The following illustrates the error (hover the mouse over the error text to see that the problem is due to "-long" ) and how it may be avoided.

Displaying parts of a conversion

The following examples show how to display only a part of the output.

Convert Output Description
{{convert|2|cuyd|m3}} 2 cubic yards (1.5 m3) normal convert
{{convert|2|cuyd|m3|abbr=values}} 2 (1.5) input and output values
{{convert|2|cuyd|m3|disp=unit}} cubic yards input unit
{{convert|2|cuyd|m3|disp=unit|adj=on}} cubic-yard input unit, adjectival (hyphenated)
{{convert|2|cuyd|cuyd|0|disp=out|abbr=off}} 2 cubic yards input (workaround)
{{convert|2|cuyd|m3|disp=unit2}} m3 output unit (symbol)
{{convert|2|cuyd|m3|disp=unit2|abbr=off}} cubic metres output unit (name)
{{convert|2|cuyd|m3|disp=number}} 1.5 output value
{{convert|2|cuyd|m3|disp=out}} 1.5 m3 output value and unit
{{convert|2|cuyd|m3|abbr=off|disp=out}} 1.5 cubic metres output value and unit

Flipping the order of output

To invert the order of measurements, simply use |order=flip

Wrapping and line breaking

Convert uses the regular space (" ") and non-breaking space (&nbsp; which shows: " ") to control line-breaking (also called wrapping/nowrapping).

In all examples below, an &nbsp; is shown as "_" (red underscore): "3_ft".

Wrapping is possible where a regular space (" ") is used. Prevent wrapping is enforced in the template using the non-breaking space, that ties and keeps text elements together.

3 feet may break after "3"
3&nbsp;ft, or Template:Replace, will not break after "3"
A line break (Template:Purple) forces a newline (line break), and so overrules any nowrap setting at that point.

Word meaning:

In measurements, SI uses wording that says that value = number × unit, for example length = number × meter.
In {{Convert}} documentation, sometimes 'value' is uses to mean the number; and abbr is used to mean unit symbol(s).
Within a single measured value (number and unit)

The separator between the number and the unit can be a space or a nonbreaking space (&nbsp;):

{{convert|12|m|ft|abbr=on}}Template:Replace
{{convert|12|m|ft}}Template:Replace
This can be set (overruled) to be &nbsp; by |adj=j (for 'join').
{{convert|12|m|ft|adj=j}}Template:Replace
{{convert|3|acre|m2|abbr=on}}Template:Replace
{{convert|3|acre|m2|adj=j}}Template:Replace
{{convert|1|ft|6|in|cm}}Template:Replace
{{convert|2|m|ftin}}Template:Replace
{{convert|2|m|ftin|adj=on}}Template:Replace
{{convert|12|e6m}}Template:Replace
Between measurements
{{convert|3|ft|m}}Template:Replace
{{convert|12|in|cm|disp=sqbr|abbr=on}}Template:Replace (&nbsp; before "[")
{{convert|2|acre|m2 sqft ha}}Template:Replace
Between components of a measurement (e.g., in a range; between foot–inch)
{{convert|1|ft|6|in|cm}}Template:Replace
{{convert|12|to|20|in|cm}}Template:Replace
{{convert|12|or|20|in|cm}}Template:Replace
{{convert|12|+/-|2|in|cm}}Template:Replace
{{convert|12|,|20|in|cm}}Template:Replace
{{convert|12|to-|20|in|cm}}Template:Replace
{{convert|12|x|20|in|cm}}Template:Replace
Overrule by setting a line break
{{convert|12|m|ft|disp=br}}12 metresTemplate:Purple39 feet shows:
Template:Replace
Preview wikicode

To see the wikicode result of the convert template: put your {{convert|...}} code into Special:ExpandTemplates and then preview by clicking OK.

Tables

The following parameters are intended for use in tables.

Parameter Description
|disp=table for a table cell with align="right"
|disp=tablecen for a table cell with align="center"
|sortable=on output a numeric hidden sort field for a sortable table

The following shows the wikitext output by some example converts.

Convert Resulting wikitext
{{convert|47.5|kg|lb}} 47.5 kilograms (105 lb)
{{convert|47.5|kg|lb|disp=table}} align="right"|47.5
|align="right"|105
{{convert|47.5|kg|lb|disp=tablecen}} align="center"|47.5
|align="center"|105
{{convert|47.5|kg|lb|sortable=on}} <span style="display:none">7001475000000000000</span>47.5 kilograms (105 lb)

Fixed table

This wikitext:

{|class="wikitable"
! align=right, rowspan="2" |
!colspan="2"| Length
!colspan="2"| Weight
|- style="vertical-align:bottom;"
!metres !!ft in !!kg !!lb
|-
! Lorem ipsum
| {{convert|28.1|m|ftin|disp=table}}
| {{convert|47.5|kg|lb|disp=table}}
|-
! Dolor sit amet
| {{convert|9.9|m|ftin|disp=table}}
| {{convert|74.1|kg|lb|disp=table}}
|-
! Consectetur
| {{convert|38.2|m|ftin|disp=table}}
| {{convert|31.5|kg|lb|disp=table}}
|-
! Adipisicing elit
| {{convert|18.7|m|ftin|disp=table}}
| {{convert|52.7|kg|lb|disp=table}}
|}

produces this table:

Length Weight
metres ft in kg lb
Lorem ipsum 28.1 92 ft 2 in 47.5 105
Dolor sit amet 9.9 32 ft 6 in 74.1 163
Consectetur 38.2 125 ft 4 in 31.5 69
Adipisicing elit 18.7 61 ft 4 in 52.7 116

Sortable table

This wikitext:

{|class="wikitable sortable"
! align=right, rowspan="2" |
!colspan="2"| Length
!colspan="2"| Weight
|- style="vertical-align:bottom;"
!metres !!ft in !!kg !!lb
|-
! Lorem ipsum
| {{convert|28.1|m|ftin|disp=table|sortable=on}}
| {{convert|47.5|kg|lb|disp=table|sortable=on}}
|-
! Dolor sit amet
| {{convert|9.9|m|ftin|disp=table|sortable=on}}
| {{convert|74.1|kg|lb|disp=table|sortable=on}}
|-
! Consectetur
| {{convert|38.2|m|ftin|disp=table|sortable=on}}
| {{convert|31.5|kg|lb|disp=table|sortable=on}}
|-
! Adipisicing elit
| {{convert|18.7|m|ftin|disp=table|sortable=on}}
| {{convert|52.7|kg|lb|disp=table|sortable=on}}
|}

produces this table:

Length Weight
metres ft in kg lb
Lorem ipsum 28.1 92 ft 2 in 47.5 105
Dolor sit amet 9.9 32 ft 6 in 74.1 163
Consectetur 38.2 125 ft 4 in 31.5 69
Adipisicing elit 18.7 61 ft 4 in 52.7 116

Units in singular or plural

Unit symbols are always singular. Unit names can be singular or plural. A unit is singular when the number is exactly +1:

Note: as of November 2014, in certain conditions this topic can behave unexpected (bug).

Setting |adj=1 makes these values singular: (−1 <= v and v < 0) or (0 < v and v <= 1)

Parameter list

Template:Convert/doc/parameter list

Complicated grammar

This example is from article Fort McHenry:

The American defenders had 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons.

This result cannot reasonably be produced by {{convert}}. However, convert can be used to construct the required text.

An alternative to subst would be to enter {{convert|18|,|24|,|32|lb|kg|0}} into Special:ExpandTemplates, then copy and edit its result into the article.

Deprecated

Template:Convert/doc/deprecations list

Limitations

This is a list of features that the module may be expected to support, but which will not work.

Composite units cannot be used in a range:

If an expression is wanted, it has to use {{#expr:...}}:

Template:Convert navs Template:Help navigation