Difference between revisions of "Template:Convert/doc"

From Teampedia
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
This template converts measurements from one unit and presents the results.
+
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
 +
__NOTOC__
 +
==Purpose==
  
For example:
+
To show quantities in a primary and secondary display, such as {{convert|32|m|ft|1}}, or {{convert|18|°C|°F|1}}.
  
{{t|convert|1|km|mi}} → {{convert|1|km|mi}}<br>
+
== Usage ==
{{t|convert|7|mi|km}} → {{convert|7|mi|km}}
+
<tt><nowiki>{{</nowiki>convert|''original_value''|''original_unit''|''conversion_unit''|''round_to''<nowiki>}}</nowiki></tt>
 
+
;Usage
+
Basic examples:
+
  
 +
== Examples ==
 
{| 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
+
 
|-
 
|-
|<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|20.5|sqkm|sqmi|1|lk=on|abbr=on}}</nowiki>||{{convert|20.5|sqkm|sqmi|1|lk=on|abbr=on}}
 
|-
 
|-
|<nowiki>{{convert|100|mpgus}}</nowiki>||{{convert|100|mpgus}}
+
|<nowiki>{{convert|641|acre|sqmi|3|lk=on|abbr=on}}</nowiki>||{{convert|641|acre|sqmi|3|lk=on|abbr=on}}
 
|-
 
|-
|<nowiki>{{convert|120|km/h}}</nowiki>||{{convert|120|km/h}}
+
|''However''||
 
|-
 
|-
|<nowiki>{{convert|18|°C|°F}}</nowiki>||{{convert|18|°C|°F}}
+
|<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.
 +
|}
 +
 
 +
===Tricks===
 +
{| class="wikitable"
 
|-
 
|-
|<nowiki>{{convert|-15|C|F}}</nowiki>||{{convert|-15|C|F}}
+
! colspan="2" | <big>'''In order to...'''</big>
 
|-
 
|-
|<nowiki>{{convert|9|e6USgal|abbr=off}}</nowiki>||{{convert|9|e6USgal|abbr=off}}<br>The "e6" scales the input to millions; the "abbr=off" yields the "mega" in the output.<br>Scaling is only available for Single value conversions.  Not all units are supported.
+
| Use [[United States|U.S.]] spelling || attach <code><nowiki>|sp=us</nowiki></code>
 
|-
 
|-
| <nowiki>{{convert|1250|sqft|m2|lk=in|sigfig=2}}</nowiki> ||{{convert|1250|sqft|m2|lk=in|sigfig=2}}<br/>
+
| 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).
 
|-
 
|-
|<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, [[cu yd]].
+
| Use the singular for grammar || attach <code><nowiki>|sing=on</nowiki></code> (ex: "The 190 foot (58 m) bridge" as opposed to "feet")
 
|-
 
|-
|<nowiki>{{convert|641|acre|ha sqmi|lk=on}}</nowiki>||{{convert|641|acre|ha sqmi|lk=on}}
+
| Abbreviate all units || attach <code><nowiki>|abbr=on</nowiki></code>
 
|-
 
|-
|<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.
+
| Use a / instead ( ) || attach <code><nowiki>|disp=slash</nowiki></code> (or shorthand: <code><nowiki>|disp=/</nowiki></code>) (ex: 190&nbsp;foot/58&nbsp;m)
 
|}
 
|}
  
More documentation can be found at [[wikipedia:Template:Convert/doc]].
+
===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"
 +
|-
 +
! colspan="5" | <big>Units supported by {{tl|convert}}</big>
 +
|-
 +
| '''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>
 +
|-
 +
! 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 ||
 +
|-
 +
! 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 ||
 +
|-
 +
! 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 ||
 +
|-
 +
! 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 ||
 +
|}
 +
 
 +
==Example/monitor page==
 +
Monitor quality or look at examples at [[Template:Convert/check]]
 +
 
 +
<includeonly>
 +
<!-- 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>[[Category:Experimental templates|{{PAGENAME}}]][[Category:Inline templates]]</includeonly><noinclude>[[Category:Template documentation|{{PAGENAME}}]]</noinclude>
+
</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