Difference between revisions of "Template:Convert/doc"

From Teampedia
Jump to: navigation, search
(Created page with "{{documentation subpage}} <includeonly>{{intricate}}</includeonly> <!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE --> <!-- -- For parameter descriptions, use | to sho...")
 
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{documentation subpage}}
 
<includeonly>{{intricate}}</includeonly>
 
 
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
 
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
<!--
+
__NOTOC__
  -- For parameter descriptions, use &#124; to show bar "|"
+
==Purpose==
  -- otherwise, table will freak.
+
  --
+
  -- -->
+
{{notice|[[Template:Convert]] and most of its high-risk subtemplates have been protected so that only [[Wikibooks:Administrators|admins]] can edit them. Discuss proposed changes on the [[Template talk:Convert|Convert discussion page]].}}
+
  
=== Usage ===
+
To show quantities in a primary and secondary display, such as {{convert|32|m|ft|1}}, or {{convert|18|°C|°F|1}}.
This template shows measurement quantities as primary and converted secondary units (or ranges), with optional rounding, wikilinks, abbreviation, or UK spellings, and various separators including:&nbsp; parentheses "(&nbsp;)", "or", hyphens, comma, "to" or dashes. The can help users by generating correct conversions from one unit of measurement to another, particularly for more complex units. It's also useful by making the text adhere to books' [[Help:Local manuals of style|manuals of style]]. The text the template generates does not differ from a plain text equivalent, however.
+
  
Styles include: distance "{{convert|32|m|ft}}" and "{{convert|32|m|ft|disp=or}}"; temperature "{{convert|18|°C|°F}}"; mass "{{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]].
+
== Usage ==
 +
<tt><nowiki>{{</nowiki>convert|''original_value''|''original_unit''|''conversion_unit''|''round_to''<nowiki>}}</nowiki></tt>
  
{|
+
== Examples ==
|- style="background:#FAFEFF; vertical-align:top;"
+
|Options&nbsp;include:&nbsp;||[[#lk_in|<code>lk=in</code>]], [[#abbr_on|<code>abbr=on</code>]], [[#abbr_on|<code>abbr=off</code>]], [[#sp_uk|<code>sp=uk</code>]], [[#adj_on|<code>adj=on</code>]], [[#adj_on|<code>adj=mid</code>]], [[#disp_or|<code>disp=x</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, such as "<code>&#124;1</code>" to show tenths or "<code>&#124;-2</code>" to show full 100's, etc.
+
|}
+
'''Single value''':
+
<tt><nowiki>{{</nowiki>convert|''value''|''in_unit''|''out_unit''|''round_to''<nowiki>|...}}</nowiki></tt>
+
 
+
'''Range of 2 values, or set of 3''' (see below for list of ''range'' options):
+
<tt>
+
{&#123;convert|''val1''|''range''|''val2'' |''in_unit''|''out_unit''|''round_to''|...}}
+
{&#123;convert/3 |''val1''|''range''|''val2''|''words''|''val3''|''in_unit''|''out_unit''|''round_to''|...}}</tt>
+
* Numbers must be entered in unformatted form (without commas). 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).
+
* Optional parameters, in examples below, allow abbreviated units (abbr=on), or U.K. spellings (sp=uk for ''metre''), 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 very limited in-built capacity for [[w:dimensional analysis|dimensional analysis]].  It is therefore up to the user to ensure that most input and output units are compatible.  Do not, for example, attempt to convert barrels to tonnes.  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.  Note also that the code <code>lb</code> gives pounds mass, for pounds force use <code>lbf</code>.
+
* 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====
+
 
{| class="wikitable"
 
{| class="wikitable"
 
|'''Input'''||'''Displays as'''
 
|'''Input'''||'''Displays as'''
 
|-
 
|-
|<nowiki>{{convert|3.21|kg|lb}}</nowiki>||{{convert|3.21|kg|lb}}
+
|<nowiki>{{convert|32|m|ft|0}}</nowiki>||{{convert|32|m|ft|0}}
 
|-
 
|-
|<nowiki>{{convert|3.21|kg|lb|0}}</nowiki>||{{convert|3.21|kg|lb|0}}
+
|<nowiki>{{convert|18|°C|°F|1}}</nowiki>||{{convert|18|°C|°F|1}}
 
|-
 
|-
|<nowiki>{{convert|10|kg|lb|disp=or}}</nowiki>||{{convert|10|kg|lb|disp=or}}
+
|<nowiki>{{convert|10|mi|km|0}}</nowiki>||{{convert|10|mi|km|0}}
 
|-
 
|-
|<nowiki>{{convert|6|ft|5|in|m}}</nowiki>||{{convert|6|ft|5|in|m}}
+
|<nowiki>{{convert|25|km|mi|0}}</nowiki>||{{convert|25|km|mi|0}}
<!--This is currently broken, see talk page
+
 
|-
 
|-
|<nowiki>{{convert|2|m|ftin}}</nowiki>||{{convert|2|m|ftin}}
+
|<nowiki>{{convert|1|lb|kg|0}}</nowiki>||{{convert|1|lb|kg|0}}
-->
+
 
|-
 
|-
|<nowiki>{{convert|10|mi}}</nowiki>||{{convert|10|mi}}
+
| <nowiki>{{convert|1250|sqft|sqm|1|lk=on}}</nowiki> ||{{convert|1250|sqft|sqm|1|lk=on}}
|-
+
|<nowiki>{{convert|100|mpgus}}</nowiki>||{{convert|100|mpgus}}
+
|-
+
|<nowiki>{{convert|120|km/h}}</nowiki>||{{convert|120|km/h}}
+
|-
+
|<nowiki>{{convert|18|°C|°F}}</nowiki>||{{convert|18|°C|°F}}
+
|-
+
| <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.
+
 
|-  
 
|-  
|<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, [[w:cu yd|cu yd]].
+
|<nowiki>{{convert|20.5|sqkm|sqmi|1|lk=on|abbr=on}}</nowiki>||{{convert|20.5|sqkm|sqmi|1|lk=on|abbr=on}}
 
|-
 
|-
|<nowiki>{{convert|641|acre|ha sqmi|lk=on}}</nowiki>||{{convert|641|acre|ha sqmi|lk=on}}<br />Note 'lk=on' links all units. Common units should not be linked.
+
|<nowiki>{{convert|641|acre|sqmi|3|lk=on|abbr=on}}</nowiki>||{{convert|641|acre|sqmi|3|lk=on|abbr=on}}
 
|-
 
|-
|<nowiki>{{convert|641|acre|ha sqmi|2|lk=on}}</nowiki>||{{convert|641|acre|ha 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.
+
|''However''||
|}
+
 
+
====Range of 2 values====
+
:''Note: not yet operational for all units''
+
{| class="wikitable"
+
|'''Input'''||'''Displays as'''
+
|-
+
|<nowiki>{{convert|60|and|170|kg|lb}}</nowiki>||{{convert|60|and|170|kg|lb}}
+
|-
+
|<nowiki>{{convert|60|to|170|kg|lb}}</nowiki>||{{convert|60|to|170|kg|lb}}
+
|-
+
|<nowiki>{{convert|60|to(-)|170|kg|lb}}</nowiki>||{{convert|60|to(-)|170|kg|lb}}
+
|-
+
|<nowiki>{{convert|60|-|170|kg|lb}}</nowiki>||{{convert|60|-|170|kg|lb}}
+
|-
+
|<nowiki>{{convert|41|to|50|F|C}}</nowiki>||{{convert|41|to|50|F|C}}
+
|-
+
|<nowiki>{{convert|41|-|50|F|K}}</nowiki>||{{convert|41|-|50|F|K}}
+
|-
+
|<nowiki>{{convert|60|x|120|m|ft}}</nowiki>||{{convert|60|x|120|m|ft}}
+
|-
+
|<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=off}}</nowiki>||{{convert|4|-|9|L|USgal|abbr=off}}
+
|-
+
|}<!--NOTE: rows require "nowiki", using &#123;{ disappears. -->
+
 
+
The following conversions are currently not available as a range of values:
+
*Some imperial and US gallon-based units
+
*Other fuel-consumption units, except "mpg" or "L100km" shown above.
+
*Large scale units (e3, e6, e9)
+
*Combination-based units (ft&in, st&lb, lb&oz) due to complexity of the conversion.
+
 
+
====Range/set of 3 values====
+
:''Note: not yet operational for all units''
+
{| class="wikitable"
+
|'''Input'''||'''Displays as'''
+
|-
+
|<nowiki>{{convert/3 |2|x|4|x|6|m|ft}}</nowiki>||{{convert/3 |2|x|4|x|6|m|ft}}
+
|-
+
|<nowiki>{{convert/3 |60|-|70|-|80|kg|lb}}</nowiki>||{{convert/3|60|-|70|-|80|kg|lb}}
+
|-
+
|<nowiki>{{convert/3 |60|to|80|or|85|m|ft}}</nowiki>||{{convert/3 |60|to|80|or|85|m|ft}}
+
|-
+
|<nowiki>{{convert/3 |11|by|15|rarely|16|ft|m}}</nowiki>||{{convert/3 |11|by|15|rarely|16|ft|m}}
+
|-
+
|<nowiki>{{convert/3 |41|to|50|to|60|F|C}}</nowiki>||{{convert/3 |41|to|50|to|60|F|C}}
+
 
|-
 
|-
|<nowiki>{{convert/3 |41|-|50|almost|51|F|K}}</nowiki>||{{convert/3 |41|-|50|almost|51|F|K}}
+
|<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.
 
|}
 
|}
For {&#123;convert/3}}, the separator words can be any text.
 
  
===Parameters===
+
===Tricks===
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! colspan="2" | Parameters
+
! colspan="2" | <big>'''In order to...'''</big>
 
|-
 
|-
| {{anchor|sp_uk}}Use [[w:British English|UK spelling]]  
+
| Use [[United States|U.S.]] spelling || attach <code><nowiki>|sp=us</nowiki></code>
| attach <code><nowiki>|sp=uk</nowiki></code>
+
 
|-
 
|-
| {{anchor|lk_in}}Make units linked
+
| 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).
| attach <code><nowiki>|lk=on</nowiki></code> &nbsp; to link all units (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 />([[Wikibooks:Dewikify]] suggests that you should not link common units of measurement).
+
 
|-
 
|-
| {{anchor|adj_on}}Use the adjective form, or insert mid-text words
+
| Use the singular for grammar || attach <code><nowiki>|sing=on</nowiki></code> (ex: "The 190 foot (58 m) bridge" as opposed to "feet")
| attach <code><nowiki>|adj=on</nowiki></code> (e.g. "190-foot (58 m) bridge" instead of "190 feet...").
+
:: This produces the adjective form—the unit name in the singular with a hyphen.
+
attach <code><nowiki>|adj=mid</nowiki></code> (e.g. "190-foot bridge (58 m)" as: |adj=mid|bridge
+
:: or "190-foot-long bridge (58 m)" as: |adj=mid|-long bridge)
+
Note 1: Any rounding-parameter should follow the mid-text: "text|0".<br>Note 2: For adj=mid, must specify both input & output unit-codes.
+
:: For example, to convert feet, use "ft|m" or "ft|0":<br>&nbsp; &bull; <nowiki>{{convert|9|ft|m|adj=mid|-long}}</nowiki> &rarr; 9-foot-long (2.7 m)<br>To default the output unit-code, set parameter 3 to: 0.
+
 
|-
 
|-
| Abbreviate units, or not
+
| Abbreviate all units || attach <code><nowiki>|abbr=on</nowiki></code>
| {{anchor|abbr_on}}attach <code><nowiki>|abbr=on</nowiki></code> to show unit symbols<br /> attach <code><nowiki>|abbr=off</nowiki></code> &nbsp; to show all unit names in full words<br /> attach <code><nowiki>|abbr=in</nowiki></code> to abbreviate input units<br /> attach <code><nowiki>|abbr=out</nowiki></code> to abbreviate output units<br /> attach <code><nowiki>|abbr=values</nowiki></code> to suppress unit names & show only values. So, <nowiki>{{convert|6|mi|abbr=values}}</nowiki> gives: {{convert|6|mi|abbr=values}}.
+
 
|-
 
|-
| {{anchor|disp_or}}Change "( )" to display other separators
+
| Use a / instead ( ) || attach <code><nowiki>|disp=slash</nowiki></code> (or shorthand: <code><nowiki>|disp=/</nowiki></code>) (ex: 190&nbsp;foot/58&nbsp;m)
| attach <code>&#124;disp=comma</code> to put comma, not brackets/parentheses<br /> attach <code>&#124;disp=or</code> to put "or" between units.<br /> The default value is:&nbsp; disp=b for brackets/parentheses.
+
|-
+
| Change "( )" to customized separators
+
| attach <code>&#124;disp=x&#124; (begin &#124; end)</code> to show "xx (begin yy end)" See example 1<br /> attach <code>&#124;disp=x&#124;;</code> to show "xx; yy" See example 2<br /> attach <code>&#124;disp=x&#124; (same as &#124;)</code> to show "xx (same as yy)". See example 3<br />Example 1: {{nowrap|<nowiki>{&#123;convert|9|km|mi|disp=x| [|]}}</nowiki>}}&rarr;{{nowrap|9 kilometres [5.6 mi]}} (note space before <nowiki>[|</nowiki>)<br />Example 2: {{nowrap|<nowiki>{&#123;convert|9|km|mi|disp=x|;}}</nowiki>}}&rarr;{{nowrap|9 kilometres;5.6 mi}}<br />Example 3: {{nowrap|<nowiki>{&#123;convert|10|km|mi|disp=x| (about |)}}</nowiki>}}&rarr;{{nowrap|10 kilometres (about 6.2 mi)}} (note spaces used within the code).
+
|-
+
| Display output only
+
| attach <code>&#124;disp=output only</code> to show result number & unit<br /> attach <code>&#124;disp=output number only</code> to show just number<br />Note when using "disp=output only" then the unit name can still be shown as full words by abbr=off or linked by lk=on.
+
|-
+
| Display units inverted as reverse order
+
| attach <code>&#124;disp=flip</code>&nbsp; to reverse the order & show output unit first.<br />So, <nowiki>{{convert|6|km|disp=flip}}</nowiki> shows "3.7 miles (6 km)".<br />To get symbol "mi" use abbr=in, to abbreviate the input unit (left-side unit).
+
|-
+
| Display unit name (only)
+
| attach <code>&#124;disp=unit</code> 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.
+
|-
+
| {{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>.
+
|-
+
| Round to a specified number of [[w:significant figures|significant figures]]
+
| attach <code><nowiki>|sigfig={some integer greater than zero}</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.
+
|-
+
| Round by 5
+
| attach <tt>&#124;disp=5</tt> &nbsp;to round the output amount to the nearest 5 units. Not supported for all options.
+
|-
+
| Let ''Convert'' decide the unit to convert to|| skip the ''precision'' parameter (the 3rd or 4th unnamed parameter) e.g. <code><nowiki>{{convert|100|km|kn}}</nowiki></code> gives ''{{convert|100|km|kn}}'' and <code><nowiki>{{convert|100|km}}</nowiki></code> gives ''{{convert|100|km}}''.
+
|-
+
|Display input value with a fraction
+
| <nowiki>{{convert|3/8|in|mm|3|abbr=on}}</nowiki> &rarr; {{convert|3/8|in|mm|3|abbr=on}} or <nowiki>{{convert|11+1/4|in|cm|2|abbr=on}}</nowiki> &rarr; {{convert|11+1/4|in|cm|2|abbr=on}}
+
For negative amounts, use two minus signs (hyphens): -11-1/4.
+
|-
+
|{{anchor|sortable_on}}Generate a hidden sort key for use with a [[Help:Tables#Sortable_tables|sortable table]]
+
| attach <code><nowiki>|sortable=on</nowiki></code> to generate a hidden sort key so that [[Help:Tables#Sortable_tables|sortable tables]] will sort correctly. This uses {{tl|ntsh}} to generate a sort key from the first numeric value. It ignores any additional values, i.e., 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, i.e.: 5, 10, 15 instead of 10, 15, 5.
+
 
|}
 
|}
  
====Parameters still under construction====
+
===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 {{tl|convert}}.
 +
----
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! colspan="2" | Parameters still under construction.  May not work in all situations
+
! colspan="5" | <big>Units supported by {{tl|convert}}</big>
 
|-
 
|-
| disp=5<ref name=temp group=note>This is a limited, temporary option, until an alternative can be implemented.</ref> || The output will be rounded to the nearest 5 units. Might not work when linking unit names.
+
| '''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>
 
|-
 
|-
|disp=tablecen<ref name=temp group=note/>||Similar to disp=table except that the values will be centered within the column.
+
! colspan="5" style="font-size: 110%; text-align: left;" | '''Area'''
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | '''[[International System of Units|SI]]''' || [[square metre]] || sqm || m² || square meter
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | → || [[square kilometre]] || sqkm || km² || square kilometer
 +
|- 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) ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[square foot]] ||sqft || sq&nbsp;ft ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[square yard]] ||sqyd || sq&nbsp;yd ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[square mile]] || sqmi || sq&nbsp;mi ||
 +
|- style="font-size: 90%; background-color: #FFFFFF;"
 +
| style="text-align: center;" | → || [[square nautical mile]] || sqnmi || sq&nbsp;nmi ||
 +
|- style="font-size: 90%;"
 +
| style="text-align: center;" | '''old metric''' || [[hectare]] || ha || ha ||
 
|-
 
|-
|disp=comma<ref name=temp group=note/>||The two values will be separated by a comma, for situations where the first value is already within parentheses.
+
! 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 ||
 
|-
 
|-
|abbr=in||Abbreviates only the input unit.
+
! 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 ||
 
|-
 
|-
|abbr=out||Abbreviates only the output unit.
+
! colspan="5" style="font-size: 110%; text-align: left;" | '''Temperature'''
|-
+
|- style="font-size: 90%;"
|abbr=comma<ref name=temp group=note/>||"Abbreviates" (removes) commas. For ranges, using abbr=comma conflicts with internal options, so instead, append "nocomma" to a range-word: tonocomma, bynocomma, andnocomma, -nocomma & xnocomma.
+
| style="text-align: center;" | '''SI''' || [[kelvin]] || K || K ||
|-
+
|- style="font-size: 90%;"
|abbr=mos||For ranges, abbreviates with the input unit repeated, twice.
+
| style="text-align: center;" | → || [[degrees Celsius]] || °C (C) || °C ||
|-
+
|- style="font-size: 90%; background-color: #FFFFFF;"
|disp=br||This separates input and output units with a forced line break. This can be useful in tables with limited horizontal space.
+
| style="text-align: center;" | '''Imperial & U.S.&nbsp;Customary''' || [[degrees Rankine]] || °R (R) || °R ||
|-
+
|- style="font-size: 90%; background-color: #FFFFFF;"
|disp=sqbr||Shows [[w:square brackets|square brackets]] "[&nbsp;]" instead of parentheses "(&nbsp;)" in output. Example: 55 miles [89&nbsp;km]. This option can be used in direct quotes, to show conversions in editorial brackets. See: attach <code>&#124;disp=x&#124;[&#124;]</code>, above, as another way of showing brackets "[&nbsp;]".
+
| style="text-align: center;" | → || [[degrees Fahrenheit]] || °F (F) || °F ||
 
|}
 
|}
{{reflist|group=note}}
 
  
===Rounding===
+
==Example/monitor page==
''Convert'' supports four types of rounding:
+
Monitor quality or look at examples at [[Template:Convert/check]]
;Rounding to a given 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 {{frac|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 integer greater than zero}</nowiki></code> as noted above.
 
 
;Default rounding
 
:If neither the desired precision nor the desired number of significant figures is 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.
 
 
{| class="wikitable"
 
|-
 
! colspan="3" | Examples of default rounding
 
|-
 
|'''Input'''||'''Displays as'''||'''Note'''
 
|-
 
|<nowiki>{{convert|550|ft|m|0}}</nowiki>||{{convert|550|ft|m|0}}  || Approximate value is 167.64 m
 
|-
 
|<nowiki>{{convert|550|ft|m}}</nowiki>||{{convert|550|ft|m}} || Rounds to 170, when approximate value is 167.64 m
 
|-
 
|<nowiki>{{convert|500|ft|m|0}}</nowiki>||{{convert|500|ft|m|0}}  ||  Approximate value is 152.4 m
 
|-
 
|<nowiki>{{convert|500|ft|m}}</nowiki>||{{convert|500|ft|m}}  ||  Rounds to 150, when approximate value is 152.4 m
 
|}<!--NOTE: rows require "nowiki", using &#123;{ disappears. -->
 
 
=== Units supported ===
 
<div style="height: 400px; overflow: auto; padding: 3px; border: 1px solid #aaa;">
 
{{Convert/list of units}}
 
</div>
 
==See also==
 
* {{tl|Metricate}}
 
 
<includeonly>
 
<includeonly>
 
<!-- ADD CATEGORIES BELOW THIS LINE -->
 
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Function templates|{{PAGENAME}}]]
+
[[Category:SI unit templates|{{PAGENAME}}]]
 
+
[[Category:Conversion templates| ]]
 
<!-- ADD INTERWIKIS BELOW THIS LINE -->
 
<!-- ADD INTERWIKIS BELOW THIS LINE -->
 +
[[no:Mal:Convert]]
 +
[[zh:Template:Convert]]
  
 
</includeonly>
 
</includeonly>

Latest revision as of 16: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