Template:Convert/doc

Template convert calculates measurements from one unit (you can enter) to another one, and then presents the results. For example:
 * &rarr; 2 km
 * &rarr; 7 mi

The available units are listed below. Multiple formatting and calculation options are listed below.

Unit name or symbol (abbreviation): 1 pound or 1 lb?
By default, the first value shows unit name, the second the symbols (= abbreviation). Use on/off to change this behaviour:
 * &rarr; 1 lb (To compare; default: first value shows unit name)
 * &rarr; 1 lb
 * &rarr; 1 lb


 * in toggles the default behaviour (out):
 * &rarr; 1 lb

Adjective: a 10-mile distance
Use on to produce the adjective form. The difference:
 * &rarr; 10 mi to go. (To compare, default)
 * &rarr; A 10 mi distance. (Adjective form)

Rounding: 100 ft is 30 m or 30.5 m or 30.48 m?
In detail, it is 100 ft. In practical use, it is common to round the calculated metric number. With that, there are several possibilities.

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 below).

Convert supports four types of rounding:

Round to a given precision: use precision
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/undefined$ 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.

Round to a given number of significant figures: use sigfig
To specify the output number to be with n significant figures use &lt;number>: Setting &lt;=0 is meaningless
 * To compare: 1200 ft &rarr; 1200 ft
 * 1200 ft &rarr; 1200 ft
 * 1200 ft &rarr; 1200 ft
 * 1200 ft &rarr; 1200 ft
 * 1200 ft &rarr; 1200 ft
 * 1200 ft &rarr; 1200 ft

Round to a multiple of 5: 15, 20, 25, ...
Using 5 rounds the outcome to a multiple of 5.
 * &rarr; 10 m
 * &rarr; 10 m

Similar: using 25 rounds the outcome to a multiple of 25.
 * &rarr; 10 m
 * &rarr; 10 m
 * To compare:  &rarr; 10 m

In a range, one can round each value individually to the default. Use each:
 * &rarr; 10 x 200 x 3000 m
 * &rarr; 10 x 200 x 3000 m

Round to a multiple of a given fraction: $2 3/16$ inch
Specify the desired denominator using &lt;some positive integer&gt;. (Denominator is the below-the-slash number, for example the 3 in $1/3$).
 * &rarr; 5.56 cm
 * &rarr; 8 cm

The fraction is reduced when possible:
 * &rarr; 8 cm
 * &rarr; 8 cm (To compare)

Rounding the temperatures &deg;C, &deg;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.
 * &rarr; 10 C

Note
 * For a temperature difference, like to convert "A rise of 20 &deg;C", use 20 &tc.
 * &rarr; A rise of 20 C-change


 * To compare: "A temperature of 20 &deg;C" would yield: A temperature of 20 C

Into multiple units: 10 C
Separate the multiple output units by a space:
 * &rarr; 10 C
 * &rarr; 5 km

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:

Multiple dimensions: 6 by 12 feet (1.8 by 3.7 m)

 * &rarr; 6 by
 * &rarr; 6 x

This is the correct way in science, using  and on
 * &rarr; 6 x

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:
 * &rarr; 1 ft (to compare)
 * &rarr; 1 ft

Spell out numbers: ten miles
To write a number in words, use in:
 * &rarr; 10 mi

To spell out both in and out values, use on:
 * &rarr; 10 mi

To make first letter a capital, use In, On
 * &rarr; 10 mi
 * &rarr; 10 mi

Remember that the spelling of the units (ft, m) is independently set by abbr. To the extreme:
 * &rarr; 10 mi

Spelling of units: UK metre or US meter?
Default spelling of units is en-UK. To show en-US spelling, use us:
 * &rarr; 1 m -- default
 * &rarr; 1 m

Extra words: 4 planted acres

 * Incomplete section
 * &rarr; 4 acre

Extra adjective words: A 10 ft corridor

 * &rarr; 10 ft

Grammatical construction: The 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons
This example is from article Fort McHenry:

This formatted result is not possible straightforward by using. However, it can be made in three steps.
 * Step 1: Enter the input numbers and units in just to get the calculated output:
 * &rarr; had 18, 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 template.
 * For this, '''add
 * As a check: the preview result should show the conversion correct, with the numbers still right.
 * Now save this.
 * &rarr; had 18, 24, 32 pounds (8, 11, 15 kg) cannons
 * Step 3: When opening the edit screen again, you'll see that the text is there in code. The template itself has disappeared. You can change the text as needed. The edit screen text is:
 * You can edit this text to add the grammar:
 * After saving your edit, it shows:
 * &rarr; "had 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons".
 * After saving your edit, it shows:
 * &rarr; "had 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons".
 * &rarr; "had 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons".

Using SI prefixes: gigameter (Gm), micrometer (μm)
Units can have SI prefixes like:  for giga-, kilo-, milli-, micro- multiplication factors. The symbol (letter) is added to the unit, the word is added to the name: Gm and gigameter.

To illustrate, these are trivial calculations (from meter to meter), displaying the multiplication factor:
 * 12 Gm
 * 12 μm

The prefix can be added before an SI unit (here: unit  for meter):
 * &rarr; 12 Gm
 * : 12 Mm
 * : 12 km
 * : 12 mm
 * : 12 μm
 * : 12 um (letter "u" can be used for "μ" here)

The prefix can be used in the output unit:
 * &rarr; 12000 mi
 * &rarr; 12 in

As an exception, the non-SI unit inch can have the "μ" prefix too)
 * &rarr; 12 μm



Input with fractions: 1+1/2 in
The number to convert can be written in fractions:
 * ) is accepted:
 * sign
 * and repeat it:
 * to the unit:
 * → 7 e6m

The same is possible for the output unit:
 * → 23,000,000 ft

Any standard unit (not a combination, multiple, or built-in) can have a prefix:
 * (thousand),  (million),   (billion),   (trillion),   (quadrillion).

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:
 * → 1,234,567 m
 * → 1,234,567 m
 * → 1 234 567 m ❌

Set off to remove the separator:
 * → 1234567 m

Use gaps to set digit grouping by gap in larger numbers (thousands separator):
 * → 1234567 m (To compare, default)
 * → 1234567 m

Setting 5 or gaps5 will only add the separator when the number of digits is 5 or more:
 * → 1234 m (To compare, default)
 * → 1234 m
 * → 1234567 m
 * → 1234 m
 * → 1234567 m

Output with horizontal fraction bar in: $1⁄2$ inch
Using a double slash returns a horizontal bar fraction:
 * → 1//2 in
 * → 2+1//2 in

Brackets and separators: 10 m [33 ft]
Punctuation that distinguishes the two measurements is set by disp.

Options are:  (the default),  ,  ,  ,  ,  :
 * &rarr; 10 m --  brackets are the default
 * &rarr; 10 m
 * &rarr; 10 m
 * &rarr; 10 m

Setting br will force a new line


 * &rarr; 10 m

Setting x allows any text as separator:


 * &rarr; 10 m -- (To display spaces, use )

Flipping (reordering) the two measurements: 1 mi
Setting flip will flip (swap) the two measurements:
 * &rarr; 1 mi (To compare, default)
 * &rarr; 1 mi

When converting to multiple units, the effect is:
 * &rarr; 10 km
 * &rarr; 10 km

Displaying parts of the result: 2 cuyd
It is possible to display only parts of the conversion result:

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 table splits the result over two columns:
 * &rarr; 10 m

tablecen does the same, and also centers the text:
 * &rarr; 20 m

The units are added as a column header:
 * {| class=wikitable

! style="width:10em;" | ! style="width:10em;" | m ! style="width:10em;" | ft
 * table
 * 10 m
 * tablecen
 * 20 m
 * &lt;other> (default)
 * 30 m
 * }
 * &lt;other> (default)
 * 30 m
 * }

Sorting

 * Use both table on to produce table columns (pipe symbols), with sortable table column. As of January 2013, only the first (lefthand) column will sort (improvements pending).


 * 10 m &rarr;


 * This shows the hidden numerical sortkey:


 * {| class="wikitable sortable"

! m ! ft
 * 15+3/4 m
 * 15.5 m
 * 16.0 m
 * 16 m
 * }
 * 16.0 m
 * 16 m
 * }
 * }

TemplateData
{ "description": "Converts measurements to other units.", "params": { "1": { "label": "value", "description": "the value to convert", "type": "number" }, "2": { "label": "from unit", "description": "", "type": "string/line" }, "3": { "label": "to units", "description": "the unit to convert into", "type": "string/line" }, "4": { "label": "precision or suffix", "description": "significant digits after decimal dot or, if negative, exponent of ten", "type": "number" }, "lk": { "label": "link units", "description": "“on” all, “in” input, “out” output or “off” no units", "default": "off", "type": "string/line" }, "abbr": { "label": "abbreviation", "description": "display for the units: “on” unit symbols, “off” all unit names in full words, “in” input unit symbol, “out” abbreviated output units, “values” no units at all", "default": "out", "type": "string/line" }, "sp": { "label": "spelling", "description": "“us” display U.S. spelling of unit names", "type": "string/line" }, "adj": { "label": "adjective", "description": "adjective form (singular unit name appended by hyphen) “on” or “mid” to put conversion at end", "type": "string/line" }, "disp": { "label": "conversion", "description": "display conversion result: “or” after ‘or’, “x” with custom prefix and suffix, “b” in parentheses, “table”/“tablecen”, “output only” alone, “output number only” alone and without unit, “unit” not at all but input unit; if the value is a number it is used as precision", "default": "b", "type": "string/line" }, "order": { "label": "ordering", "description": "“flip” returns converted value first, input value second.", "type": "string/line" }, "sigfig": { "label": "significant figures", "description": "number that sets the number of significant figures", "type": "number" }, "round": { "label": "rounding output", "description": "“5” rounds the output number to nearest multiple of 5, “25” to nearest multiple of 25, “each” rounds each number in a range", "type": "string/line" }, "comma": { "label": "thousands separator", "description": "Sets or suppresses thousand separator in the numbers. “off” = no separator; “gaps”: use space not comma; “5” and “gaps5”: only add separator when number > 5 positions (10,000 or more)", "default": "on", "type": "string/line" }, "sortable": { "label": "sort key", "description": "“on” generates a hidden sort key", "type": "string/line" } }}