Difference between revisions of "Template:Convert/doc"

From Teampedia
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{documentation subpage}}
+
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
=== Units of measurement usage on Wikivoyage ===
+
__NOTOC__
Format and conventions used for units can be found at [[Wikivoyage:Measurements]].
+
==Purpose==
  
To ensure units are displayed correctly, the simplified individual template should be used.
+
To show quantities in a primary and secondary display, such as {{convert|32|m|ft|1}}, or {{convert|18|°C|°F|1}}.
  
The Convert template can be used in cases where standard format is not optimum.
+
== Usage ==
==== Simplified unit of measurement templates ====
+
<tt><nowiki>{{</nowiki>convert|''original_value''|''original_unit''|''conversion_unit''|''round_to''<nowiki>}}</nowiki></tt>
*{{tl|km}} , {{tl|mi}}
+
*{{tl|m}} , {{tl|ft}}, {{tl|yd}}
+
*{{tl|mm}} , {{tl|in}}
+
*{{tl|ha}} , {{tl|acre}}
+
* {{tl|km2}} , {{tl|mi2}}
+
* {{tl|m2}} , {{tl|ft2}}
+
* {{tl|kmh}} , {{tl|mph}}
+
* {{tl|kg}} , {{tl|lb}}
+
* {{tl|g}} , {{tl|oz}}
+
* {{tl|C}} , {{tl|F}}
+
 
+
=== Convert template usage ===
+
'''Template {{tl|convert}}''' ''calculates'' measurements from one unit (you can enter) to another one, and then ''presents the results''. For example:
+
:<code><nowiki>{{convert|2|km|mi}}</nowiki></code> → {{convert|2|km|mi}}
+
:<code><nowiki>{{convert|7|mi|km}}</nowiki></code> → {{convert|7|mi|km}}<br />
+
 
+
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 {{para|abbr|on/off}} to change this behaviour:
+
:<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}}
+
:<code><nowiki>{{convert|1|lb|kg|abbr=off}}</nowiki></code> → {{convert|1|lb|kg|abbr=off}}
+
* {{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}}
+
 
+
==Adjective: ''a 10-mile distance''==
+
Use {{para|adj|on}} to produce the adjective form. The difference:
+
:<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)''
+
 
+
==Rounding: ''100 ft'' is ''30&nbsp;m'' or ''30.5&nbsp;m'' or ''30.48&nbsp;m''?==
+
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.
+
 
+
===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]]).
+
  
 +
== Examples ==
 
{| class="wikitable"
 
{| class="wikitable"
 +
|'''Input'''||'''Displays as'''
 
|-
 
|-
! colspan="3" | Examples of rounding
+
|<nowiki>{{convert|32|m|ft|0}}</nowiki>||{{convert|32|m|ft|0}}
 
|-
 
|-
|'''Input'''||'''Displays as'''||'''Note'''
+
|<nowiki>{{convert|18|°C|°F|1}}</nowiki>||{{convert|18|°C|°F|1}}
 
|-
 
|-
|<nowiki>{{convert|123|ft|m|-1}}</nowiki>||{{convert|123|ft|m|-1}} ||
+
|<nowiki>{{convert|10|mi|km|0}}</nowiki>||{{convert|10|mi|km|0}}
 
|-
 
|-
|<nowiki>{{convert|123|ft|m|0}}</nowiki>||{{convert|123|ft|m|0}} ||
+
|<nowiki>{{convert|25|km|mi|0}}</nowiki>||{{convert|25|km|mi|0}}
 
|-
 
|-
|<nowiki>{{convert|123|ft|m|1}}</nowiki>||{{convert|123|ft|m|1}} ||
+
|<nowiki>{{convert|1|lb|kg|0}}</nowiki>||{{convert|1|lb|kg|0}}
 
|-
 
|-
|<nowiki>{{convert|550|ft|m|0}}</nowiki>||{{convert|550|ft|m|0}} || Approximate value is 167.64 m
+
| <nowiki>{{convert|1250|sqft|sqm|1|lk=on}}</nowiki> ||{{convert|1250|sqft|sqm|1|lk=on}}
 +
|-
 +
|<nowiki>{{convert|20.5|sqkm|sqmi|1|lk=on|abbr=on}}</nowiki>||{{convert|20.5|sqkm|sqmi|1|lk=on|abbr=on}}
 
|-
 
|-
|<nowiki>{{convert|550|ft|m}}</nowiki>||{{convert|550|ft|m}} || Rounds to 170, when approximate value is 167.64 m
+
|<nowiki>{{convert|641|acre|sqmi|3|lk=on|abbr=on}}</nowiki>||{{convert|641|acre|sqmi|3|lk=on|abbr=on}}
 
|-
 
|-
|<nowiki>{{convert|500|ft|m|0}}</nowiki>||{{convert|500|ft|m|0}} || Approximate value is 152.4 m
+
|''However''||
 
|-
 
|-
|<nowiki>{{convert|500|ft|m}}</nowiki>||{{convert|500|ft|m}} || Rounds to 150, when approximate value is 152.4 m
+
|<nowiki>{{convert|641|acre|sqmi|2|lk=on|abbr=on}}</nowiki>||{{convert|641|acre|sqmi|2|lk=on|abbr=on}} because 640 acres equals one square mile; 641 acres rounded to 2 would equal 1.00&nbsp;sq&nbsp;mi. Therefore it is displayed as 1&nbsp;sq&nbsp;mi.
|}<!--NOTE: rows require "nowiki", using &#123;{ disappears. -->
+
|}
 
+
''Convert'' supports four types of rounding:
+
 
+
===Round to a given precision: ''use {{para|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/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.
+
 
+
===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?) -->
+
  
 +
===Tricks===
 
{| class="wikitable"
 
{| class="wikitable"
! Convert !! Output !! Description
 
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3}}</nowiki></code> || {{convert|2|cuyd|m3}} || Default, to compare
+
! colspan="2" | <big>'''In order to...'''</big>
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|abbr=values}}</nowiki></code> || {{convert|2|cuyd|m3|abbr=values}} || Input and output numbers
+
| Use [[United States|U.S.]] 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
+
| Make units [[Wikipedia:Manual of Style (links)|wikilinked]] || attach <code><nowiki>|lk=on</nowiki></code> (The [[WP:MOS|manual of style]] suggests that you only link the first instance).
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit|adj=on}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit|adj=on}} || Input unit, adjective (hyphenated)
+
| Use the singular for grammar || attach <code><nowiki>|sing=on</nowiki></code> (ex: "The 190 foot (58 m) bridge" as opposed to "feet")
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|cuyd|0|disp=out|abbr=off}}</nowiki></code> || {{convert|2|cuyd|cuyd|0|disp=out|abbr=off}} || Input (''workaround'')
+
| Abbreviate all units || attach <code><nowiki>|abbr=on</nowiki></code>
 
|-
 
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit2}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit2}} || Output unit (symbol)
+
| Use a / instead ( ) || attach <code><nowiki>|disp=slash</nowiki></code> (or shorthand: <code><nowiki>|disp=/</nowiki></code>) (ex: 190&nbsp;foot/58&nbsp;m)
|-
+
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit2|abbr=off}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit2|abbr=off}} || Output unit (name)
+
|-
+
| <code><nowiki>{{convert|2|cuyd|m3|disp=number}}</nowiki></code> || {{convert|2|cuyd|m3|disp=number}} || Output value
+
|-
+
| <code><nowiki>{{convert|2|cuyd|m3|disp=out}}</nowiki></code> || {{convert|2|cuyd|m3|disp=out}} || Output value and unit
+
|-
+
| <code><nowiki>{{convert|2|cuyd|m3|disp=out|abbr=off}}</nowiki></code> || {{convert|2|cuyd|m3|disp=ou|abbr=offt}} || Output value and unit
+
 
|}
 
|}
  
==Table options==
+
===Rounding===
For the wikitable structure, there are two options: split over columns and make the table sortable.
+
The number given for rounding rounds off the result to the power of 1/10 the rounding 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.
===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:
+
== Conversions ==
:<code><nowiki>{{convert|20|m|ft|disp=tablecen}}</nowiki></code> → {{convert|20|m|ft|disp=tablecen}}
+
The abbreviations to the right of the units are the abbreviations that can be entered when using the template.  Through various revisions of this template, some units have incorporated multiple abbreviations to make the code more flexible for editors, e.g. °F ''or'' F may be entered.    Though they may not be the correct abbreviations, the ''correct abbreviation'' will always be displayed when you use {{tl|convert}}.
 
+
----
The units are added as a column header:
+
{| class="wikitable"
:{| class=wikitable
+
! style="width:10em;" | &nbsp;
+
! style="width:10em;" | m
+
! style="width:10em;" | ft
+
 
|-
 
|-
| {{para|disp|table}}
+
! colspan="5" | <big>Units supported by {{tl|convert}}</big>
| {{convert|10|m|ft|disp=table}}
+
 
|-
 
|-
|{{para|disp|tablecen}}
+
| '''system''' || '''unit''' || '''abbreviation ''used in coding'''''<br> (alternative abbreviations) || '''abbreviation ''printed''''' || [[Image:Flag of the United States.svg|20px]] '''US spelling''' <code><nowiki>|sp=us</nowiki></code>
| {{convert|20|m|ft|disp=tablecen}}
+
 
|-
 
|-
|{{para|disp|&lt;other>}} <small>(default)</small>
+
! colspan="5" style="font-size: 110%; text-align: left;" | '''Area'''
|{{convert|30|m|ft|disp=}}
+
|- style="font-size: 90%;"
|}
+
| style="text-align: center;" | '''[[International System of Units|SI]]''' || [[square metre]] || sqm || m² || square meter
 
+
|- style="font-size: 90%;"
===Sorting===
+
| style="text-align: center;" | → || [[square kilometre]] || sqkm || km² || square kilometer
: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).
+
|- style="font-size: 90%; background-color: #FFFFFF;"
 
+
| style="text-align: center;" | '''[[Imperial system|Imperial]] & [[United States customary units|U.S.&nbsp;Customary]]''' || [[acre]] || acre || acre (or acres) ||
:<nowiki>{{convert|10|m|ft|disp=table|sortable=on}}</nowiki>
+
|- style="font-size: 90%; background-color: #FFFFFF;"
<code>{{nowrap|{{convert|10|m|ft|disp=table|sortable=on}}}}</code>
+
| style="text-align: center;" | || [[square foot]] ||sqft || sq&nbsp;ft ||
:This shows the hidden numerical sortkey:
+
|- style="font-size: 90%; background-color: #FFFFFF;"
<code>align="right"|&lt;span style="display:none">7001100000000000000&lt;/span>10 |align="right"|33</code>
+
| style="text-align: center;" | → || [[square yard]] ||sqyd || sq&nbsp;yd ||
 
+
|- style="font-size: 90%; background-color: #FFFFFF;"
:{| class="wikitable sortable"
+
| style="text-align: center;" | → || [[square mile]] || sqmi || sq&nbsp;mi ||
! m
+
|- style="font-size: 90%; background-color: #FFFFFF;"
! ft
+
| style="text-align: center;" | → || [[square nautical mile]] || sqnmi || sq&nbsp;nmi ||
|-
+
|- style="font-size: 90%;"
| {{convert|15+3/4|m|ft|disp=table|sortable=on}}
+
| style="text-align: center;" | '''old metric''' || [[hectare]] || ha || ha ||
 
|-
 
|-
| {{convert|15.5|m|ft|disp=table|sortable=on}}
+
! colspan="5" style="font-size: 110%; text-align: left;" | '''Length'''
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | '''SI''' || [[millimetre]] || mm || mm || millimeter
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | → || [[centimetre]] || cm || cm || centimeter
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | → || [[metre]] || m || m || meter
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | → || [[kilometre]] || km || km || kilometer
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | '''Imperial & U.S.&nbsp;Customary''' || [[inch]] || in || in ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[foot (unit of length)|foot]] || ft || ft ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[yard]] || yd || yd ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[mile]] || mi || mi ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[nautical mile]] || nmi || nmi ||
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | '''Other''' || [[astronomical unit]] || AU || AU ||
 
|-
 
|-
| {{convert|16.0|m|ft|disp=table|sortable=on}}
+
! colspan="5" style="font-size: 110%; text-align: left;" | '''Speed'''
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | '''SI''' || [[metres per second]] || m:s (m/s) || m/s || meter per second
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | → || [[kilometres per hour]] || km:h (km/h ''or'' kph)|| km/h || kilometer per hour
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | '''Accepted ''non''-SI''' || [[knot (speed)|knot]] || knot || kt ||
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | '''Imperial & U.S.&nbsp;Customary''' || [[feet per second]] || ft:s (ft/s) || ft/s ||
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | → || [[miles per hour]] || mi:h (mph ''or'' mi/h) || mph ||
 
|-
 
|-
| {{convert|16|m|ft|disp=table|sortable=on}}
+
! colspan="5" style="font-size: 110%; text-align: left;" | '''Temperature'''
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | '''SI''' || [[kelvin]] || K || K ||
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | → || [[degrees Celsius]] || °C (C) || °C ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | '''Imperial & U.S.&nbsp;Customary''' || [[degrees Rankine]] || °R (R) || °R ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[degrees Fahrenheit]] || °F (F) || °F ||
 
|}
 
|}
  
==Parameter list==
+
==Example/monitor page==
{{convert/doc/parameter list}}
+
Monitor quality or look at examples at [[Template:Convert/check]]
  
 
<includeonly>
 
<includeonly>
[[Category:Formatting and function templates‎]]
+
<!-- ADD CATEGORIES BELOW THIS LINE -->
 +
[[Category:SI unit templates|{{PAGENAME}}]]
 +
[[Category:Conversion templates| ]]
 +
<!-- ADD INTERWIKIS BELOW THIS LINE -->
 +
[[no:Mal:Convert]]
 +
[[zh:Template:Convert]]
 +
 
 
</includeonly>
 
</includeonly>

Latest revision as of 15:44, 11 April 2020


Purpose

To show quantities in a primary and secondary display, such as 32 metres (105 ft), or 18 °C (64.4 °F).

Usage

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

Examples

Input Displays as
{{convert|32|m|ft|0}} 32 metres (105 ft)
{{convert|18|°C|°F|1}} 18 °C (64.4 °F)
{{convert|10|mi|km|0}} 10 miles (16 km)
{{convert|25|km|mi|0}} 25 kilometres (16 mi)
{{convert|1|lb|kg|0}} 1  (Expression error: Unexpected round operator. )
{{convert|1250|sqft|sqm|1|lk=on}} 1,250 square feet (116.1 )
{{convert|20.5|sqkm|sqmi|1|lk=on|abbr=on}} 20.5 km² (7.9 sq mi)
{{convert|641|acre|sqmi|3|lk=on|abbr=on}} 641 acres (1.002 sq mi)
However
{{convert|641|acre|sqmi|2|lk=on|abbr=on}} 641 acres (1 sq mi) because 640 acres equals one square mile; 641 acres rounded to 2 would equal 1.00 sq mi. Therefore it is displayed as 1 sq mi.

Tricks

In order to...
Use U.S. spelling attach |sp=us
Make units wikilinked attach |lk=on (The manual of style suggests that you only link the first instance).
Use the singular for grammar attach |sing=on (ex: "The 190 foot (58 m) bridge" as opposed to "feet")
Abbreviate all units attach |abbr=on
Use a / instead ( ) attach |disp=slash (or shorthand: |disp=/) (ex: 190 foot/58 m)

Rounding

The number given for rounding rounds off the result to the power of 1/10 the rounding 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.

Conversions

The abbreviations to the right of the units are the abbreviations that can be entered when using the template. Through various revisions of this template, some units have incorporated multiple abbreviations to make the code more flexible for editors, e.g. °F or F may be entered. Though they may not be the correct abbreviations, the correct abbreviation will always be displayed when you use {{convert}}.


Units supported by {{convert}}
system unit abbreviation used in coding
(alternative abbreviations)
abbreviation printed 20px US spelling |sp=us
Area
SI square metre sqm square meter
square kilometre sqkm km² square kilometer
Imperial & U.S. Customary acre acre acre (or acres)
square foot sqft sq ft
square yard sqyd sq yd
square mile sqmi sq mi
square nautical mile sqnmi sq nmi
old metric hectare ha ha
Length
SI millimetre mm mm millimeter
centimetre cm cm centimeter
metre m m meter
kilometre km km kilometer
Imperial & U.S. Customary inch in in
foot ft ft
yard yd yd
mile mi mi
nautical mile nmi nmi
Other astronomical unit AU AU
Speed
SI metres per second m:s (m/s) m/s meter per second
kilometres per hour km:h (km/h or kph) km/h kilometer per hour
Accepted non-SI knot knot kt
Imperial & U.S. Customary feet per second ft:s (ft/s) ft/s
miles per hour mi:h (mph or mi/h) mph
Temperature
SI kelvin K K
degrees Celsius °C (C) °C
Imperial & U.S. Customary degrees Rankine °R (R) °R
degrees Fahrenheit °F (F) °F

Example/monitor page

Monitor quality or look at examples at Template:Convert/check