Help:Convert/parameter options

{{hatnote|This page may be incomplete or not up to date. Core overviews are Help:Convert and :Template:Convert (documentation)}}

This page wants to give an elaborate overview of the {{tlx|convert}}} parameters and their options. It is a technical overview.

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:

  • |N (where N is a number) to specify the number of digits to be displayed after the decimal mark (round output to N decimal places)
  • |-N (where -N is a negative number) to specify the number of digits before the decimal mark that should be replaced with zero (round output to nearest 10N).
  • |sigfig=N (where N is a positive number) to specify the number of significant digits (round output to N significant figures)
  • |round=5 to round the output to the nearest multiple of 5

Examples:

  • {{convert|1234|ft|m}} → {{convert|1234|ft|m}}
  • {{convert|1234|ft|m|2}} → {{convert|1234|ft|m|2}}
  • {{convert|1234|ft|m|-1}} → {{convert|1234|ft|m|-1}}
  • {{convert|1234|ft|m|round=5}} → {{convert|1234|ft|m|round=5}}
  • {{convert|1234|ft|m|sigfig=2}} → {{convert|1234|ft|m|sigfig=2}}
  • {{convert|1234|ft|m|sigfig=4}} → {{convert|1234|ft|m|sigfig=4}}
  • {{convert|1230|ft|m}} → {{convert|1230|ft|m}}
  • {{convert|1230|ft|m|0}} → {{convert|1230|ft|m|0}}
  • {{convert|1230|ft|m|1}} → {{convert|1230|ft|m|1}}
  • {{convert|5670|sqft}} → {{convert|5670|sqft}}
  • {{convert|5670|sqft|-2}} → {{convert|5670|sqft|-2}}

Spell

;Use US (en-US) spelling for unit names

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

  • {{convert|6|km}} → {{convert|6|km}}
  • {{convert|6|km|sp=us}} → {{convert|6|km|sp=us}}

;Spell out numbers in words

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

  • {{convert|5|mi|km|spell=in}} → {{convert|5|mi|km|spell=in}}
  • {{convert|5|mi|km|spell=in|abbr=off|0}} → {{convert|5|mi|km|spell=in|abbr=off|0}}
  • {{convert|5|mi|km|spell=In|0}} → {{convert|5|mi|km|spell=In|0}}
  • {{convert|5|mi|km|spell=In|abbr=off|0}} → {{convert|5|mi|km|spell=In|abbr=off|0}}
  • {{convert|2+1/4|mi|km|abbr=off|0|spell=In}} → {{convert|2+1/4|mi|km|abbr=off|0|spell=In}}
  • {{convert|2+1/4|mi|km|abbr=off|0|spell=In|sp=us}} → {{convert|2+1/4|mi|km|abbr=off|0|spell=In|sp=us}}

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

  • {{convert|5|mi||0|order=flip|spell=in}} → {{convert|5|mi||0|order=flip|spell=in}}
  • {{convert|5|mi||0|order=flip|spell=In|abbr=off}} → {{convert|5|mi||0|order=flip|spell=In|abbr=off}}

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

Both input and output values can be spelled:

  • {{convert|5|mi|m|-2|spell=on|sp=us|abbr=off}} → {{convert|5|mi|m|-2|spell=on|sp=us|abbr=off}}
  • {{convert|5|mi|m|-2|spell=On|sp=us|abbr=off}} → {{convert|5|mi|m|-2|spell=On|sp=us|abbr=off}}

Fractions

An input value can be specified as a fraction.

  • {{convert|1/2|in|mm|1}} → {{convert|1/2|in|mm|1}}
  • {{convert|1/2|in|mm|1|adj=on}} → {{convert|1/2|in|mm|1|adj=on}}
  • {{convert|2+1/2|in|mm|1}} → {{convert|2+1/2|in|mm|1}}
  • {{convert|-2-1/4|in|mm|1}} → {{convert|-2-1/4|in|mm|1}}
  • {{convert|1/2|in|mm|1|spell=in}} → {{convert|1/2|in|mm|1|spell=in}}

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

  • {{convert|1//2|in|mm|1}} → {{convert|1//2|in|mm|1}}
  • {{convert|2+1//2|in|mm|1}} → {{convert|2+1//2|in|mm|1}}

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.

  • {{convert|219|mm|in|abbr=on}} → {{convert|219|mm|in|abbr=on}}
  • {{convert|219|mm|in|abbr=on|frac=2}} → {{convert|219|mm|in|abbr=on|frac=2}}
  • {{convert|219|mm|in|abbr=on|frac=4}} → {{convert|219|mm|in|abbr=on|frac=4}}
  • {{convert|219|mm|in|abbr=on|frac=8}} → {{convert|219|mm|in|abbr=on|frac=8}}
  • {{convert|222|mm|in|abbr=on|frac=8}} → {{convert|222|mm|in|abbr=on|frac=8}}

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.

  • {{convert|18.45|in|m|frac=2}} → {{convert|18.45|in|m|frac=2}}
  • {{convert|18.45|in|ft in hand cm|frac=2}} → {{convert|18.45|in|ft in hand cm|frac=2}}
  • {{convert|18.45|in|ft in hand cm|frac=2|1}} → {{convert|18.45|in|ft in hand cm|frac=2|1}}

Joins

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

class="wikitable"

! Convert !! Output !! Description

{{convert|2.4|m|ft}}{{convert|2.4|m|ft}}default
{{convert|2.4|m|ft|disp=b}}{{convert|2.4|m|ft|disp=b}}brackets (same as default)
{{convert|2.4|m|ft|disp=sqbr}}{{convert|2.4|m|ft|disp=sqbr}}square brackets
{{convert|2.4|m|ft|disp=or}}{{convert|2.4|m|ft|disp=or}}or
{{convert|2.4|m|ft|disp=comma}}{{convert|2.4|m|ft|disp=comma}}comma
{{convert|2.4|m|ft|disp=br}}{{convert|2.4|m|ft|disp=br}}"<br />", line break

Ranges

{{Convert/doc/range separator list}}

The following ranges provide different output when units are abbreviated.

class="wikitable"

! Convert !! Output

{{convert|3|and(-)|6|ft|abbr=on}}{{convert|3|and(-)|6|ft|abbr=on}}
{{convert|3|to(-)|6|ft|abbr=on}}{{convert|3|to(-)|6|ft|abbr=on}}
{{convert|3|x|6|ft|abbr=on}}{{convert|3|x|6|ft|abbr=on}}

Ranges can use more than two values.

class="wikitable"

! Convert !! Output

{{convert|3|x|4|x|24|in}}{{convert|3|x|4|x|24|in}}
{{convert|3|x|4|to|6+1/2|x|8+3/4|in}}{{convert|3|x|4|to|6+1/2|x|8+3/4|in}}

Ranges can be specified in the first parameter.

class="wikitable"

! Convert !! Output

{{convert|3.2-7.5|ha}}{{convert|3.2-7.5|ha}}
{{convert|3x4x24|in}}{{convert|3x4x24|in}}

Extra words

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

class="wikitable"

! Convert !! Output !! Description

{{convert|4|ftadj=mid
long}}{{convert|4|ftadj=mid
long}}adjectival with mid-text between input and output
{{convert|40|acreadj=pre|planted}}{{convert|40|acreadj=pre|planted}}text before the input unit
{{convert|4|mdisp=preunit|+ }}{{convert|4|mdisp=preunit|+ }}same text before the input and output units
{{convert|4|mdisp=preunit|+ |or more }}{{convert|4|mdisp=preunit|+ |or more }}different text before the input and output units
{{convert|20|impflozdisp=x|, approximately }}{{convert|20|impflozdisp=x|, approximately }}text before the output (replaces the join)
{{convert|100|mdisp=x|/day (|/day)}}{{convert|100|mdisp=x|/day (|/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.

  • {{convert|4|ft|adj=mid|-long}} → {{convert|4|ft|adj=mid|-long}}
  • {{convert|4|ft||adj=mid|-long}} → {{convert|4|ft||adj=mid|-long}}
  • {{convert|4|ft| |adj=mid|-long}} → {{convert|4|ft| |adj=mid|-long}}
  • {{convert|4|ft|m|adj=mid|-long}} → {{convert|4|ft|m|adj=mid|-long}}

Displaying parts of a convert

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

class="wikitable"

! Convert !! Output !! Description

{{convert|2|cuyd|m3}}{{convert|2|cuyd|m3}}normal convert
{{convert|2|cuyd|m3|abbr=values}}{{convert|2|cuyd|m3|abbr=values}}input and output values
{{convert|2|cuyd|m3|disp=unit}}{{convert|2|cuyd|m3|disp=unit}}input unit
{{convert|2|cuyd|m3|disp=unit|adj=on}}{{convert|2|cuyd|m3|disp=unit|adj=on}}input unit, adjectival (hyphenated)
{{convert|2|cuyd|cuyd|0|disp=out|abbr=off}}{{convert|2|cuyd|cuyd|0|disp=out|abbr=off}}input (workaround)
{{convert|2|cuyd|m3|disp=unit2}}{{convert|2|cuyd|m3|disp=unit2}}output unit (symbol)
{{convert|2|cuyd|m3|disp=unit2|abbr=off}}{{convert|2|cuyd|m3|disp=unit2|abbr=off}}output unit (name)
{{convert|2|cuyd|m3|disp=number}}{{convert|2|cuyd|m3|disp=number}}output value
{{convert|2|cuyd|m3|disp=out}}{{convert|2|cuyd|m3|disp=out}}output value and unit
{{convert|2|cuyd|m3|abbr=off|disp=out}}{{convert|2|cuyd|m3|abbr=off|disp=out}}output value and unit

Wrapping and line breaking

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

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

::3 feet may break after "3"

::3&nbsp;ft, or {{replace|3 ft| |{{red|_}}}}, will not break after "3"

In the examples below, an &nbsp; is shown as "{{red|_}}" (red underscore): "3{{red|_}}ft".

A line break ({{purple|<br/>}}) forces a newline (line break), and so overrules any nowrap setting at that point.

;Within a measurement (value+unit)

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

  • When a unit is abbreviated (symbol is shown), the separator is &nbsp;.

::{{convert|12|m|ft|abbr=on}} → {{replace|{{convert|12|m|ft|abbr=on}}| |{{red|_}}}}

  • When a unit is not abbreviated (name is shown), the separator is a space.

::{{convert|12|m|ft}} → {{replace|{{convert|12|m|ft}}| |{{red|_}}}}

::This can be set (overruled) to be &nbsp; by {{para|adj|j}} (for 'join').

::{{convert|12|m|ft|adj=j}} → {{replace|{{convert|12|m|ft|adj=j}}| |{{red|_}}}}

  • Some units do not have a symbol and always use a space (such as acre).

::{{convert|3|acre|m2|abbr=on}} → {{replace|{{convert|3|acre|m2|abbr=on}}| |{{red|_}}}}

  • Except, option |adj=j ("join") forces the separator to be &nbsp;.

::{{convert|3|acre|m2|adj=j}} → {{replace|{{convert|3|acre|m2|adj=j}}| |{{red|_}}}}

  • Except, &nbsp; is always used when a measurement is in multiple units.

::{{convert|1|ft|6|in|cm}} → {{replace|{{convert|1|ft|6|in|cm}}| |{{red|_}}}}

::{{convert|2|m|ftin}} → {{replace|{{convert|2|m|ftin}}| |{{red|_}}}}

  • Except, if option |adj=on is used and the unit is not abbreviated, the separator is a hyphen ("-").

::{{convert|2|m|ftin|adj=on}} → {{replace|{{convert|2|m|ftin|adj=on}}| |{{red|_}}}}

  • When the name of a number is used, &nbsp; is used as the separator between the value and the name. For example, a measurement spelled as "12 million metres" has &nbsp; before "million" and a space afterwards.

::{{convert|12|e6m}} → {{replace|{{convert|12|e6m}}| |{{red|_}}}}

;Between measurements

  • A space is used as the separator in a join between the first and second measurement.

::{{convert|3|ft|m}} → {{replace|{{convert|3|ft|m}}| |{{red|_}}}}

  • Except for the special case before "[" :

::{{convert|12|in|cm|disp=sqbr|abbr=on}} → {{replace|{{convert|12|in|cm|disp=sqbr|abbr=on}}| |{{red|_}}}} (&nbsp; before "[")

  • Multiple output measurements (by listing units) always use a space between measurements ("; " has a space after ";").

::{{convert|2|acre|m2 sqft ha}} → {{replace|{{convert|2|acre|m2 sqft ha}}| |{{red|_}}}}

;Between components of a measurement (e.g., in a range; between foot–inch)

  • A measurement in multiple units always uses a space between components ("1 foot 6 inches" has &nbsp; before the unit names, but a space after "foot").

::{{convert|1|ft|6|in|cm}} → {{replace|{{convert|1|ft|6|in|cm}}| |{{red|_}}}}

  • In a range, spaces are generally used to separate items. For example, "to" and "or" have a space before and after in the following.

::{{convert|12|to|20|in|cm}} → {{replace|{{convert|12|to|20|in|cm}}| |{{red|_}}}}

::{{convert|12|or|20|in|cm}} → {{replace|{{convert|12|or|20|in|cm}}| |{{red|_}}}}

  • The ranges +/- and , always use &nbsp;:

::{{convert|12|+/-|2|in|cm}} → {{replace|{{convert|12|+/-|2|in|cm}}| |{{red|_}}}}

::{{convert|12|,|20|in|cm}} → {{replace|{{convert|12|,|20|in|cm}}| |{{red|_}}}}

  • The "to(-)" range is an exception. When a unit is not abbreviated, "to" has &nbsp; before and a space after.

::{{convert|12|to(-)|20|in|cm}} → {{replace|{{convert|12|to(-)|20|in|cm}}| |{{red|_}}}}

  • The "x" range is an exception. When a unit is abbreviated, "×" has a space before and &nbsp; after.

::{{convert|12|x|20|in|cm}} → {{replace|{{convert|12|x|20|in|cm}}| |{{red|_}}}}

;Overrule by setting a line break

  • Parameter {{para|disp|br}} adds a forced line break (<br/>) between measurements; brackets are omitted.

::{{convert|12|m|ft|disp=br}} → {{replace|{{replace|{{convert|12|m|ft|disp=br}}| |{{red|_}}}} |
|{{purple|<br/>}}
}}

;Preview wikicode

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

Tables

The following parameters are intended for use in tables.

class="wikitable"

! Parameter !! Description

|disp=tablefor a table cell with align="right"
|disp=tablecenfor a table cell with align="center"
|sortable=onoutput a numeric hidden sort field for a sortable table

The following shows the wikitext output by some example converts.

class="wikitable"

! 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:

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

=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:

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

Parameter list

{{Convert/doc/parameter list}}

Examples of number grouping:

  • {{convert|1234|m|ft}} → {{convert|1234|m|ft}}
  • {{convert|1234|m|ft|comma=5}} → {{convert|1234|m|ft|comma=5}}
  • {{convert|12345|m|ft|comma=5}} → {{convert|12345|m|ft|comma=5}}
  • {{convert|1234|m|ft|comma=gaps}} → {{convert|1234|m|ft|comma=gaps}}
  • {{convert|1234|m|ft|comma=gaps5}} → {{convert|1234|m|ft|comma=gaps5}}
  • {{convert|1,234,567|m|ft|comma=gaps5}} → {{convert|1,234,567|m|ft|comma=gaps5}}
  • {{convert|1,234,567|m|ft|comma=off}} → {{convert|1,234,567|m|ft|comma=off}}

Examples of spelling input values:

  • {{convert|10|mi|km|spell=in}} → {{convert|10|mi|km|spell=in}}
  • {{convert|10|mi|km|spell=In}} → {{convert|10|mi|km|spell=In}}
  • {{convert|1/3|mi|km|adj=on|spell=in}} → {{convert|1/3|mi|km|adj=on|spell=in}}

Differences from templates previously used

Before December 2013, {{tl|convert}} was implemented by a series of templates, not a module. Following are some differences between the new and old convert implementations.

  • Using {{subst:convert|...}} works with the module.
  • The module checks unit types and displays an error message if a mismatch occurs.
  • Ranges and all options, including order=flip, should work with all units.
  • Scaled units like e6USgal are not predefined. With some exceptions, all units accept prefixes e3, e6, e9, e12, e15.
  • The module uses an empty unit code rather than 0 to mean "use the default unit", as in {{convert|4|ft||adj=mid|-long}} (it is also possible to use {{convert|4|ft|0|adj=mid|-long}}, but that sets the output precision to zero).
  • The functionality of {{convert/3}} and {{convert/4}} is handled by the module, except that the module does not support arbitrary text to separate items in a range. Furthermore, the predefined separator words such as "by" and "to" behave in exactly the same manner as they do for standard converts, so a conversion like {{convert/3|2|x|4|x|6|m|ft}} would need to use the new * separator rather than x to produce exactly the same output with the module.
  • The module does not have a problem with template loops, and will allow pointless conversions like {{convert|123|m|m}}.

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:

  • {{convert|2|ft|6|in|to|3|ft|9|in}} → {{convert|2|ft|6|in|to|3|ft|9|in}}

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

  • {{convert|3*12|ft|mm}} → {{convert|3*12|ft|mm}}
  • {{convert|{{#expr:3*12}}|ft|mm}} → {{convert|{{#expr:3*12}}|ft|mm}}