Changes

Template:Convert/doc

16,845 bytes removed, 16:48, 29 February 2020
no edit summary
{{documentation subpage}}
<includeonly>{{intricate}}</includeonly><!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE Documentation here --><!-- -- For parameter descriptions, use &#124; to show bar "|" -- 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 ===This template shows measurement quantities as primary and converted secondary Converts Minecraft terms to real-life 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, howevervice versa.
Styles include: distance "; Parameters*{{convert|32|mp|ft1}}" and ": value to convert (e.g., ''2400'')*{{convert|32|m|ftp|disp=or2}}"; temperature ": full name of unit to convert from (e.g., ''mile'')*{{convert|18|°Cp|°F3}}"; mass "{{: full name of unit to convert|55to (e.0|kg|lb|abbr=on}}" or "g., ''kilometer'')*{{convertp|65|to|80|kg|lb|abbr=onseperator}}"; etc. For units see: [[Template:Convert/list of units|Convert/list of units]].optional seperator (defaults to a space with brackets)
; Available units{{flatlist||- style="background:#FAFEFF; vertical-align:top;"*fahrenheit|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.*celsius|}*minute'''Single value''': *second*kilograms*miles*kilometers <tt><nowiki>{{</nowiki>convert|''value''|''in_unit''|''out_unit''|''round_to''<nowiki>|...}}</nowiki></tt>
'''Range of 2 values, or set of 3''' ;Examples*(see below for list of ''range'' optionsusing defaults)– {{t|convert|5}}:<tt> {&#123;{convert|''val1''|''range''|''val2'' |''in_unit''|''out_unit''|''round_to''|...5}} *{&#123;{t|convert/3 |''val1''2400|''range''mile|''val2''kilometer|''words''|''val3''|''in_unit''|''out_unit''|''round_to''|...seperator{{=}}</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&amp;nbsp;-code a number as <nowiki>&amp;nbsp;}}: {{formatnum:9,000,500convert|2400|R}}</nowiki> (becomes 9000500).* Optional parameters, in examples below, allow abbreviated units (abbrmile|kilometer|seperator=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"
|'''Input'''||'''Displays as'''
|-
|<nowiki>{{nowrap|3.21 kg (7.07 lb)}}</nowiki>||{{nowrap|3.21 kg (7.07 lb)}}
|-
|<nowiki>{{convert|3.21|kg|lb|0}}</nowiki>||{{nowrap|3.21|kg|lb|0}}
|-
|<nowiki>{{convert|10|kg|lb|disp=or}}</nowiki>||{{convert|10|kg|lb|disp=or}}
|-
|<nowiki>{{convert|6|ft|5|in|m}}</nowiki>||{{convert|6|ft|5|in|m}}
<!--This is currently broken, see talk page
|-
|<nowiki>{{convert|2|m|ftin}}</nowiki>||{{convert|2|m|ftin}}
-->
|-
|<nowiki>{{mi to km|10}}</nowiki>||{{mi to km|10}}
|-
|<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|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|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.
|}
 
====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}}
|}
For {&#123;convert/3}}, the separator words can be any text.
 
===Parameters===
{| class="wikitable"
|-
! colspan="2" | Parameters
|-
| {{anchor|sp_uk}}Use [[w:British English|UK spelling]]
| attach <code><nowiki>|sp=uk</nowiki></code>
|-
| {{anchor|lk_in}}Make units linked
| 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
| 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
| {{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
| 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====
{| class="wikitable"
|-
! colspan="2" | Parameters still under construction. May not work in all situations
|-
| 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.
|-
|disp=tablecen<ref name=temp group=note/>||Similar to disp=table except that the values will be centered within the column.
|-
|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.
|-
|abbr=in||Abbreviates only the input unit.
|-
|abbr=out||Abbreviates only the output unit.
|-
|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.
|-
|abbr=mos||For ranges, abbreviates with the input unit repeated, twice.
|-
|disp=br||This separates input and output units with a forced line break. This can be useful in tables with limited horizontal space.
|-
|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;]".
|}
{{reflist|group=note}}
 
===Rounding===
''Convert'' supports four types of rounding:
;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>
<!-- ADD CATEGORIES BELOW THIS LINE Template categories/interwiki here -->[[Category:Function templates|{{PAGENAME}}]] <!-- ADD INTERWIKIS BELOW THIS LINE --> 
</includeonly>
<noinclude>
<!-- Documentation categories/interwiki here -->
</noinclude>