Template:Convert/doc: Difference between revisions

no edit summary
m (1 revision imported: Wikipedia article on Nicotine modules needed)
imported>DePiep
No edit summary
 
Line 15: Line 15:
2019-01-01 by TDmonthly error report: Page [article] count: 651064; Transclusion count: 2878293
2019-01-01 by TDmonthly error report: Page [article] count: 651064; Transclusion count: 2878293
-->
-->
{{hatnote|For currency conversion into US dollars, see [[Template:To USD]]}}
{{High-use}}
{{#ifeq:{{FULLPAGENAME}}|Template:Convert|{{high-risk| {{formatnum:995000}}+ }}}}
{{for|currency conversion|Template:To USD|Template:To EUR}}
{{Transwiki guide |small=yes |text=See [[Template:Convert/Transwiki guide|'''this information''']] on copying this template and modifying it for use on another wiki.}}
{{Transwiki guide |small=yes |text=See [[Template:Convert/Transwiki guide|'''this information''']] on copying this template and modifying it for use on another wiki.}}
{{Lua|Module:Convert}}
{{Lua|Module:Convert}}
'''Template {{tl|convert}}''' ''calculates'' from one measurement unit to another one, and then ''presents'' the results formatted. The complete list of unit symbols recognized by the template is at [[Module:Convert/documentation/conversion data]].
'''Template {{tl|convert}}''' calculates a measurement value (''number × unit'') into the same measurement by a different unit, and then presents the results, formatted. The complete list of unit symbols recognized by the template is [[Module:Convert/documentation/conversion data|here]].


For example:
For example:
:<code><nowiki>{{convert|2|km|mi}}</nowiki></code> → {{convert|2|km|mi}} <small>(km entered, so converted into mile)</small>
:<code><nowiki>{{convert|2|km|mi}}</nowiki></code> → {{convert|2|km|mi}} <small>(km entered, converted into miles)</small>
:<code><nowiki>{{convert|7|mi|km}}</nowiki></code> → {{convert|7|mi|km}} <small>(mi entered, so converted into km)</small>
:<code><nowiki>{{convert|7|mi|km}}</nowiki></code> → {{convert|7|mi|km}} <small>(mi entered, converted into km)</small>


''Numbers'' can be rounded, ''units'' can be abbreviated into symbols:
''Numbers'' can be rounded, ''units'' can be abbreviated into symbols:
Line 43: Line 43:
* <code><nowiki>{{convert|1|lb|kg}}</nowiki></code> → {{convert|1|lb|kg}}
* <code><nowiki>{{convert|1|lb|kg}}</nowiki></code> → {{convert|1|lb|kg}}
:[[International System of Units|SI]] units generally accept prefixes, like "m" for milli (10<sup>−3</sup>), and "M" for mega (10<sup>6</sup>)
:[[International System of Units|SI]] units generally accept prefixes, like "m" for milli (10<sup>−3</sup>), and "M" for mega (10<sup>6</sup>)
:For "per" units, use "/" (slash): kg/ha
:For "per" units, use "/" (slash): kg/ha (see [[#'per'_units:_kg/ha,_miles_per_gallon|§&nbsp;'per' units: kg/ha]] and [[#Currency per unit: $/mi → $/km|§&nbsp;Currency per unit: $/km]])
:For three-unit units, etc., see {{cl|Convert-like templates}}
:For three-unit units, etc., see {{cl|Convert-like templates}}


Line 50: Line 50:
* <code><nowiki>{{convert|1|lb|kg}}</nowiki></code> → {{convert|1|lb|kg}}
* <code><nowiki>{{convert|1|lb|kg}}</nowiki></code> → {{convert|1|lb|kg}}


Using {{para|abbr|in}} is the ''reverse behaviour'' to the default:
Using {{para|abbr|in}} shows the symbol for first (left-hand side) unit, and the name instead of the symbol for the second unit:
*<code><nowiki>{{convert|1|lb|kg|abbr=in}}</nowiki></code> → {{convert|1|lb|kg|abbr=in}}
*<code><nowiki>{{convert|1|lb|kg|abbr=in}}</nowiki></code> → {{convert|1|lb|kg|abbr=in}}


Line 58: Line 58:


===Convenience: {{tlf|cvt}} has {{para|abbr|on}} by default===
===Convenience: {{tlf|cvt}} has {{para|abbr|on}} by default===
Template {{tl|cvt}} is the same as {{tlf|convert}}, except that it has {{para|abbr|on}} as the default behaviour. In {{tlf|cvt}}, all other options are available. So:
Template {{tl|cvt}} is the same as {{tlf|convert}}, except that it has {{para|abbr|on}} as the default behavior. In {{tlf|cvt}}, all other options are available. So:
:<code><nowiki>{{cvt|1|lb|kg}}</nowiki></code> → {{cvt|1|lb|kg}}
:<code><nowiki>{{cvt|1|lb|kg}}</nowiki></code> → {{cvt|1|lb|kg}}
is equivalent to:
is equivalent to:
Line 66: Line 66:
Use {{para|adj|on}} to produce the adjectival (hyphenated) form:
Use {{para|adj|on}} to produce the adjectival (hyphenated) form:
* <code><nowiki>A {{convert|10|mi|km|adj=on}} distance</nowiki></code> → A {{convert|10|mi|km|adj=on}} distance.
* <code><nowiki>A {{convert|10|mi|km|adj=on}} distance</nowiki></code> → A {{convert|10|mi|km|adj=on}} distance.
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|10|mi|km}} to go</nowiki></code> → {{convert|10|mi|km}} to go.
* <code><nowiki>{{convert|10|mi|km}} to go</nowiki></code> → {{convert|10|mi|km}} to go.


Line 72: Line 72:
* <code><nowiki>A {{convert|9|in|cm|adj=on|abbr=on}} nail</nowiki></code> → A {{convert|9|in|cm|adj=on|abbr=on}} nail.
* <code><nowiki>A {{convert|9|in|cm|adj=on|abbr=on}} nail</nowiki></code> → A {{convert|9|in|cm|adj=on|abbr=on}} nail.


=={{anchor|Rounding}}Rounding: ''100 ft'' is ''30&nbsp;m'' or ''30.5&nbsp;m'' or ''30.48&nbsp;m''?==
==Rounding: ''100 ft'' is ''30&nbsp;m'' or ''30.5&nbsp;m'' or ''30.48&nbsp;m''?<span class="anchor" id="Rounding"></span>==
{{hatnote|See {{section link|Help:Convert#Rounding}} for a more mathematical description of the rounding options}}
{{hatnote|See {{section link|Help:Convert#Rounding}} for a more mathematical description of the rounding options}}
By definition, 100&nbsp;ft equals {{convert|100|ft|m|sigfig=4|disp=out}}. In practical use, it is common to round the calculated metric number. With that, there are several possibilities.
By definition, 100&nbsp;ft equals {{convert|100|ft|m|sigfig=4|disp=out}}. In practical use, it is common to round the calculated metric number. With that, there are several possibilities.
Line 97: Line 97:
|<code><nowiki>{{convert|500|ft|m|-1}}</nowiki></code> || {{convert|500|ft|m|-1}} ||
|<code><nowiki>{{convert|500|ft|m|-1}}</nowiki></code> || {{convert|500|ft|m|-1}} ||
|-
|-
|<code><nowiki>{{convert|500|ft|m}}</nowiki></code> || {{convert|500|ft|m}} || same output as with −1 (above), because the conversion factor is between 0.2 and 2 (hence, it should produce same double-zero precision (−2) as in the input value), but the conversion must produce two significant digits at a minimum (hence, a higher single-zero precision (−1) is used)
|<code><nowiki>{{convert|500|ft|m}}</nowiki></code> || {{convert|500|ft|m}} || same output as with <code>-1</code> (above), because the conversion factor is between 0.2 and 2 (hence, it should produce same double-zero precision (−2) as in the input value), but the conversion must produce two significant digits at a minimum (hence, a higher single-zero precision (−1) is used)
|-
|-
|<code><nowiki>{{convert|500|ft|m|0}}</nowiki></code> || {{convert|500|ft|m|0}} ||
|<code><nowiki>{{convert|500|ft|m|0}}</nowiki></code> || {{convert|500|ft|m|0}} ||
Line 107: Line 107:
|<code><nowiki>{{convert|500|ft|cm|-3}}</nowiki></code> || {{convert|500|ft|cm|-3}} ||
|<code><nowiki>{{convert|500|ft|cm|-3}}</nowiki></code> || {{convert|500|ft|cm|-3}} ||
|-
|-
|<code><nowiki>{{convert|500|ft|cm}}</nowiki></code> || {{convert|500|ft|cm}} || same output as with −3 (above), because the conversion factor is between 20 and 200 (hence, it should decrease input value's double-zero precision (−2) by 2), but the conversion must produce two significant digits at a minimum (hence, a higher triple-zero precision (−3) is used)
|<code><nowiki>{{convert|500|ft|cm}}</nowiki></code> || {{convert|500|ft|cm}} || same output as with <code>-3</code> (above), because the conversion factor is between 20 and 200 (hence, it should decrease input value's double-zero precision (−2) by 2), but the conversion must produce two significant digits at a minimum (hence, a higher triple-zero precision (−3) is used)
|-
|-
|<code><nowiki>{{convert|500|ft|cm|0}}</nowiki></code> || {{convert|500|ft|cm|0}} ||
|<code><nowiki>{{convert|500|ft|cm|0}}</nowiki></code> || {{convert|500|ft|cm|0}} ||
Line 115: Line 115:


===Round to a given precision: ''use a precision number''===
===Round to a given precision: ''use a precision number''===
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 multiple of {{frac|10}} to the power of 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.
Specify the desired precision with an integer as 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 multiple of {{frac|10}} to the power of this integer. For instance, if the result is 8621 and the rounding parameter is "−2", 8600 will be displayed. If the result is "123.456" and the parameter is "0", 123 will be displayed. Essentially a positive or zero rounding parameter specifies the number of decimal places; a negative value specifies the number of trailing zeroes.


{{Anchor|Round to a given number of significant figures}}
===Round to a given number of significant figures: ''{{para|sigfig|}}''<span class="anchor" id="Round to a given number of significant figures"></span>===
===Round to a given number of significant figures: ''{{para|sigfig|}}''===
To specify the output number to be with ''n'' significant figures use {{para|sigfig|&lt;number>}}:
To specify the output number to be with ''n'' significant figures use {{para|sigfig|&lt;number>}}:
* <code><nowiki>{{convert|1200|ft|m|sigfig=4}}</nowiki></code> → {{convert|1200|ft|m|sigfig=4}}
* <code><nowiki>{{convert|1200|ft|m|sigfig=4}}</nowiki></code> → {{convert|1200|ft|m|sigfig=4}}
Line 124: Line 123:
* <code><nowiki>{{convert|1200|ft|m|sigfig=2}}</nowiki></code> → {{convert|1200|ft|m|sigfig=2}}
* <code><nowiki>{{convert|1200|ft|m|sigfig=2}}</nowiki></code> → {{convert|1200|ft|m|sigfig=2}}
* <code><nowiki>{{convert|1200|ft|m|sigfig=1}}</nowiki></code> → {{convert|1200|ft|m|sigfig=1}}
* <code><nowiki>{{convert|1200|ft|m|sigfig=1}}</nowiki></code> → {{convert|1200|ft|m|sigfig=1}}
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|1200|ft|m}}</nowiki></code> → {{convert|1200|ft|m}}
* <code><nowiki>{{convert|1200|ft|m}}</nowiki></code> → {{convert|1200|ft|m}}
Setting {{para|sigfig}} to a value less than 1 is meaningless:
Setting {{para|sigfig}} to a value less than 1 is meaningless:
Line 137: Line 136:
* <code><nowiki>{{convert|10|m|ft}}</nowiki></code> → {{convert|10|m|ft}}
* <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}}
* <code><nowiki>{{convert|10|m|ft|round=25}}</nowiki></code> → {{convert|10|m|ft|round=25}}
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|10|m|ft|sigfig=4}}</nowiki></code> → {{convert|10|m|ft|sigfig=4}}
* <code><nowiki>{{convert|10|m|ft|sigfig=4}}</nowiki></code> → {{convert|10|m|ft|sigfig=4}}


Line 150: Line 149:
The fraction is reduced when possible:
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|frac=100}}</nowiki></code> → {{convert|8|cm|in|frac=100}}
Default behaviour uses decimal notation:
Default behavior uses decimal notation:
* <code><nowiki>{{convert|5.56|cm|in}}</nowiki></code> → {{convert|5.56|cm|in}}
* <code><nowiki>{{convert|5.56|cm|in}}</nowiki></code> → {{convert|5.56|cm|in}}


==={{anchor|Rounding temperatures}}Rounding temperatures: ''°C'', ''°F'' and ''K''===
===Rounding temperatures: ''°C'', ''°F'' and ''K''<span class="anchor" id="Rounding temperatures"></span>===
In temperatures, the conversion will be rounded either to the 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.
In temperatures, the conversion will be rounded either to the 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.


Line 163: Line 162:
#{{#invoke:DemoTemplate|convert|0|C|F K}}
#{{#invoke:DemoTemplate|convert|0|C|F K}}


The precision of the input number in example (1) is one digit, but the precision of its Kelvins expression is three, so the precision of the Fahrenheit conversion is ''made'' three (made 180...) . (1) and (2) seem to belie the fact that a {{convert|0.1|C-change|F-change|disp=x| is a |abbr=off}}, and make the 32 degrees difference shown in (1) begin to seem off somehow.
The precision of the input number in example (1) is one digit, but the precision of its kelvins expression is three, so the precision of the Fahrenheit conversion is ''made'' three (made 180...) . (1) and (2) seem to belie the fact that a {{convert|0.1|C-change|F-change|disp=x| is a |abbr=off}}, and make the 32 degrees difference shown in (1) begin to seem off somehow.
Result (1) seems off until you set the [[significant figures]] yourself with {{para|sigfig}}:
Result (1) seems off until you set the [[significant figures]] yourself with {{para|sigfig}}:
:{{#invoke:DemoTemplate|convert|10000|C|sigfig=5}}
:{{#invoke:DemoTemplate|convert|10000|C|sigfig=5}}
Line 169: Line 168:
:{{#invoke:DemoTemplate|convert|10000|C|0}}
:{{#invoke:DemoTemplate|convert|10000|C|0}}


The precision of the input number in example (2) is six, so the precision of the Fahrenheit output is, whereas before, Kelvins had determined it to be three. Examples (3) and (4) show how this can be hidden and generate questions, but it occurs there because the Kelvins conversion generated two fractional parts. (Before it was the input number that generated the fractional part.)  In example (3) the three input digits converted into five significant output digits because of the two digits after the decimal point, generated by the Kelvins conversion. This happened again in (5), but in (6) decimal fractions were neither given as input nor induced by the Kelvins conversion.
The precision of the input number in example (2) is six, so the precision of the Fahrenheit output is six now, whereas before kelvins had determined it to be three. Examples (3) and (4) show how this can be hidden and generate questions, but it occurs there because the kelvins conversion generated the fractional parts. (Before it was the input number that generated the fractional part.)  In example (3) the three input digits converted into five significant output digits because of the two digits after the decimal point, generated by the kelvins conversion. This happened again in (5), but in (6) decimal fractions were neither given as input nor induced by the kelvins conversion.


===Rounding input===
===Rounding input===
Line 179: Line 178:
* {{para|adj|ri2}}
* {{para|adj|ri2}}
* {{para|adj|ri3}}
* {{para|adj|ri3}}
Note that there is no {{para|adj|ri-1}}{{nay}} or similar for rounding above the decimal place.  Neither is there support for significant figures, multiples of 5, or any other output-rounding feature.
Note that it is not possible to round above the decimal place ({{para|adj|ri-1}}{{nay}}).  Neither is there support for significant figures, multiples of 5, or any other output-rounding feature.


The default precision is computed based on the input, so an explicit output precision must usually be supplied:
The default precision is computed based on the input, so an explicit output precision must usually be supplied:
Line 186: Line 185:


In this case, if the input were rounded before conversion, a different result would be obtained:
In this case, if the input were rounded before conversion, a different result would be obtained:
* {{tlc|convert|<nowiki>{{#expr:4.14159 round 0}}</nowiki>|mi|km|0}} → {{convert|{{#expr:4.14159 round 0}}|mi|km|0}} {{nay}} (double rounding)
* {{tlc|convert|<nowiki>{{#expr:4.14159 round 0}}</nowiki>|mi|km|0}} → {{convert|{{#expr:4.14159 round 0}}|mi|km|0}} {{nay}} (rounds intermediate calculation, giving a different result)


==Into multiple units: ''{{convert|10|C|F K}}''==
==Into multiple units: ''{{convert|10|C|F K}}''==
Line 221: Line 220:
While it is possible to enter feet, inch in a simple conversion, this is not possible for ranges:
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|x|3|ft|5|in|mm}}</nowiki></code> → {{convert|1|ft|3|in|x|3|ft|5|in|mm}} {{nay}}
* <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}} {{nay}}
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|1|ft|3|in|mm}}</nowiki></code> → {{convert|1|ft|3|in|mm}}
* <code><nowiki>{{convert|1|ft|3|in|mm}}</nowiki></code> → {{convert|1|ft|3|in|mm}}
However, converting metric units into feet and inches with {{para|order|flip}} can produce the desired output:
However, converting metric units into feet and inches with {{para|order|flip}} can produce the desired output:
Line 263: Line 262:


;Exception:
;Exception:
Entering the unit spelled <code>|foot|</code> forces singular output "foot", whatever the number is.
Entering the unit "foot" instead of "ft" forces singular output "foot", whatever the number is.
* <code><nowiki>{{convert|100|foot|abbr=off}}</nowiki></code> → {{convert|100|foot|abbr=off}}
* <code><nowiki>{{convert|100|foot|abbr=off}}</nowiki></code> → {{convert|100|foot|abbr=off}}


Line 333: Line 332:


===Scientific notation: ''1.23 × 10<sup>−14</sup>''===
===Scientific notation: ''1.23 × 10<sup>−14</sup>''===
In [[scientific notation]], a number is written like {{round|12.3e-15|16}}. The plain number has exactly one digit before the decimal point.
In [[scientific notation]], a number is written like {{val|1.23e-14}}. The plain number has exactly one digit before the decimal point.


With {{tlf|convert}}, the input can be in e-notation such as <code>12.3e4</code>. This value is displayed as a power of ten, and the output is displayed in scientific notation, except that an output value satisfying 0.01 <= v < 1000 is shown as a normal number. In addition, if the output value is 1000 and sigfig=4 is used, the value is displayed as a normal number.
With {{tlf|convert}}, the input can be in e-notation such as <code>12.3e4</code>. This value is displayed as a power of ten, and the output is displayed in scientific notation, except that an output value satisfying 0.01 <= v < 1000 is shown as a normal number. In addition, if the output value is 1000 and sigfig=4 is used, the value is displayed as a normal number.
Line 353: Line 352:
*<code><nowiki>{{convert|2-1⁄2|in|mm|1}}</nowiki></code> → {{convert|2-1⁄2|in|mm|1}}. This is interpreted as a range from 2 inches to 1⁄2 inch.
*<code><nowiki>{{convert|2-1⁄2|in|mm|1}}</nowiki></code> → {{convert|2-1⁄2|in|mm|1}}. This is interpreted as a range from 2 inches to 1⁄2 inch.
*<code><nowiki>{{convert|-2+1⁄2|in|mm|1}}</nowiki></code> → {{convert|-2+1⁄2|in|mm|1}} {{nay}} This is neither a mixed number nor a range, and mathematical expressions requiring calculations are not allowed here.
*<code><nowiki>{{convert|-2+1⁄2|in|mm|1}}</nowiki></code> → {{convert|-2+1⁄2|in|mm|1}} {{nay}} This is neither a mixed number nor a range, and mathematical expressions requiring calculations are not allowed here.
*<code><nowiki>{{convert|2+½|in|mm|1}}</nowiki></code> → {{convert|2+½|in|mm|1}} {{nay}} Fractions consisting of a single Unicode character are not allowed either.


===Horizontal fraction bar: ''{{sfrac|1|2}}&nbsp;inch''===
===Horizontal fraction bar: ''{{sfrac|1|2}}&nbsp;inch''===
Line 373: Line 373:
Use {{para|comma|gaps}} to use digit grouping by gap (thin space) as a thousands separator:
Use {{para|comma|gaps}} to use digit grouping by gap (thin space) as a thousands separator:
* <code><nowiki>{{convert|1234567|m|ft|comma=gaps}}</nowiki></code> → {{convert|1234567|m|ft|comma=gaps}}
* <code><nowiki>{{convert|1234567|m|ft|comma=gaps}}</nowiki></code> → {{convert|1234567|m|ft|comma=gaps}}
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|1234567|m|ft}}</nowiki></code> → {{convert|1234567|m|ft}}
* <code><nowiki>{{convert|1234567|m|ft}}</nowiki></code> → {{convert|1234567|m|ft}}


Line 379: Line 379:
* <code><nowiki>{{convert|1234|m|ft|comma=5}}</nowiki></code> → {{convert|1234|m|ft|comma=5}}
* <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|1234567|m|ft|comma=5}}</nowiki></code> → {{convert|1234567|m|ft|comma=5}}
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|1234|m|ft}}</nowiki></code> → {{convert|1234|m|ft}}
* <code><nowiki>{{convert|1234|m|ft}}</nowiki></code> → {{convert|1234|m|ft}}


==Output manipulation==
==Output manipulation==
===Brackets and separators: ''10 m [33 ft]''===
===Brackets and separators: ''10 m [33 ft]'' <span class="anchor" id="Brackets and separators"></span>===
Punctuation that distinguishes the two measurements is set by {{para|disp|}}.<br/>
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>br()</code>, <code>x{{!}}…</code>:
Options are: <code>b</code> <small>(the default)</small>, <code>sqbr</code>, <code>comma</code>, <code>or</code>, <code>br</code>, <code>br()</code>, <code>x{{!}}…</code>:
Line 389: Line 389:
* <code><nowiki>{{convert|10|m|ft|disp=comma}}</nowiki></code> → {{convert|10|m|ft|disp=comma}}
* <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}}
* <code><nowiki>{{convert|10|m|ft|disp=or}}</nowiki></code> → {{convert|10|m|ft|disp=or}}
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|10|m|ft}}</nowiki></code> → {{convert|10|m|ft}}
* <code><nowiki>{{convert|10|m|ft}}</nowiki></code> → {{convert|10|m|ft}}


Line 405: Line 405:
Setting {{para|order|flip}} will flip (swap) the two measurements:
Setting {{para|order|flip}} will flip (swap) the two measurements:
* <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. -->
* <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. -->
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|1|mi|m}}</nowiki></code> → {{convert|1|mi|m|sigfig=5|abbr=off}}
* <code><nowiki>{{convert|1|mi|m}}</nowiki></code> → {{convert|1|mi|m|sigfig=5|abbr=off}}


Line 422: Line 422:
It is possible to display only parts of the conversion result:
It is possible to display only parts of the conversion result:
<!-- todo: describe effect of order=flip ("out" means 1st or 2nd measurement?) -->
<!-- todo: describe effect of order=flip ("out" means 1st or 2nd measurement?) -->
The following examples show how to display only a part of the result.


{| class="wikitable"
<!-- table c/p from Help:Convert#Displaying_parts_of_a_conversion -->
! Convert !! Output !! Returns
:<small>Note: in Convert, ''abbr'' is synonym for ''unit symbol''</small>
{| class="wikitable" style="font-size:85%;"
! Convert !! Returns !! Components
|-
| <code><nowiki>{{convert|2|cuyd|m3}}</nowiki></code>
| {{convert|2|cuyd|m3}}
| all (default conversion)
|-
| <code><nowiki>{{convert|2|cuyd|m3|abbr=on}}</nowiki></code>
| {{convert|2|cuyd|m3|abbr=on}}
| all (default conversion, abbr)
|-
| <!--- return NUMBERS ONLY ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- --->
|-
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>abbr=values}}}}</code>
| {{convert|2|cuyd|m3|abbr=values}}
| numbers only
|-
| <!--- return INPUT ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- --->
|-
| <code><nowiki>{{convert|2|cuyd</nowiki>{{bg|1=yellow|2=<nowiki>|cuyd|disp=out</nowiki>}}}}</code>
| {{convert|2|cuyd|cuyd|disp=out}}
| input value (workaround)
|-
| <code><nowiki>{{convert|2|cuyd</nowiki>{{bg|1=yellow|2=<nowiki>|cuyd|disp=out|abbr=on</nowiki>}}}}</code>
| {{convert|2|cuyd|cuyd|disp=out|abbr=on}}
| input value abbr (workaround)
|-
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=unit}}}}</code>
| {{convert|2|cuyd|m3|disp=unit}}
| input unit
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3}}</nowiki></code> || {{convert|2|cuyd|m3}}
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=unit<nowiki>|</nowiki>adj=on}}}}</code>
| Regular output (for comparison)
| {{convert|2|cuyd|m3|disp=unit|adj=on}}
| input unit, adjectival (hyphenated)
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|abbr=values}}</nowiki></code>
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=unit<nowiki>|</nowiki>adj=on<nowiki>|</nowiki>abbr=on}}}}</code>
| {{convert|2|cuyd|m3|abbr=values}} || Input and output numbers
| {{convert|2|cuyd|m3|disp=unit|adj=on|abbr=on}}
| input unit, adjectival (abbr so not hyphenated)
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit}}
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=unit<nowiki>|</nowiki>abbr=on}}}}</code>
| Input unit
| {{convert|2|cuyd|m3|disp=unit|abbr=on}}
| input unit abbr
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit|adj=on}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit|adj=on}}
| <!--- return OUTPUT ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- --->
| Input unit, adjective (hyphenated)
|-
|-
| <code><nowiki>{{convert|2|cuyd|cuyd|disp=out}}</nowiki></code> || {{convert|2|cuyd|cuyd|disp=out}} || Input (''workaround''. {{nowrap|1=Note repetition of unit in input}})
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=out}}}}</code>
| {{convert|2|cuyd|m3|disp=out}}
| output value, symbols
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|abbr=~}}</nowiki></code> || {{convert|2|cuyd|m3|abbr=~}}
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=out<nowiki>|</nowiki>abbr=off}}}}</code> || {{convert|2|cuyd|m3|disp=out|abbr=off}} || output value, names
| Input: both name and symbol
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit2}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit2}} || Output unit (symbol)
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=out<nowiki>|</nowiki>adj=on|abbr=off}}}}</code> || {{convert|2|cuyd|m3|disp=out|adj=on|abbr=off}} || output, adjective
|-
|-
| <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</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=number}}}}</code> || {{convert|2|cuyd|m3|disp=number}} || output number
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=number}}</nowiki></code> || {{convert|2|cuyd|m3|disp=number}}
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=unit2}}}}</code> || {{convert|2|cuyd|m3|disp=unit2}} || output unit (abbr by default)
| Output value
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=out}}</nowiki></code> || {{convert|2|cuyd|m3|disp=out}}
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=unit2<nowiki>|</nowiki>abbr=off}}}}</code> || {{convert|2|cuyd|m3|disp=unit2|abbr=off}} || output unit (name)
| Output value and unit name
|-
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=out|abbr=off}}</nowiki></code> || {{convert|2|cuyd|m3|disp=out|abbr=off}}
| <code><nowiki>{{convert|2|cuyd|m3</nowiki>{{bg|1=yellow|2=<nowiki>|</nowiki>disp=unit2<nowiki>|</nowiki>abbr=on}}}}</code> || {{convert|2|cuyd|m3|disp=unit2|abbr=on}} || output unit (abbr)
| Output value and unit symbol
|}
|}


Line 546: Line 577:


===All units===
===All units===
{{selfref|See also: [[Template:Convert/list of units|Convert/list of units]]}}
{{selfref|See also: [[Template:Convert/list of units]]}}
{{hatnote|Units are case-sensitive: use {{xt|kW}}, not {{!xt|KW}} or {{!xt|kw}}}}
{{hatnote|Units are case-sensitive: use {{xt|kW}}, not {{!xt|KW}} or {{!xt|kw}}}}
{{Convert/list of units}}
{{Convert/list of units}}


==={{anchor|per}}'per' units: ''kg/hl'', ''miles per gallon''===
==='per' units: ''kg/ha'', ''miles per gallon''<span class="anchor" id="per"></span>===
When using a slash (<code>/</code>), a unit like <code>kg/hl</code> is recognized as kilograms ''per'' hectolitre and will be converted with other mass/volume units.
When using a slash (<code>/</code>), a unit like <code>kg/ha</code> is recognized as kilograms ''per'' hectare and will be converted in to other mass/area units. A unit in the numerator is not required.
* <code><nowiki>{{convert|1000|kg/hl}}</nowiki></code> → {{convert|1000|kg/hl}}
* <code><nowiki>{{convert|1000|kg/ha}}</nowiki></code> → {{convert|1000|kg/ha}}
* <code><nowiki>{{convert|350|/in2}}</nowiki></code> → {{convert|350|/in2}}


Population density (''inhabitants per square mile'') can be converted using
Population density (''inhabitants per square mile'') can be converted using
Line 560: Line 592:
* <code><nowiki>{{convert|26|mpgUS|l/100km mpgimp}}</nowiki></code> → {{convert|26|mpgUS|l/100km mpgimp}}
* <code><nowiki>{{convert|26|mpgUS|l/100km mpgimp}}</nowiki></code> → {{convert|26|mpgUS|l/100km mpgimp}}


==={{anchor|Units of difference}}Units of difference: Expressing a change or difference in temperature===
===Units of difference: Expressing a change or difference in temperature<span class="anchor" id="Units of difference"></span>===
We have already discussed standard temperature conversions (°C, °F, K), as shown in these two examples:
We have already discussed standard temperature conversions (°C, °F, K), as shown in these two examples:
* {{#invoke:DemoTemplate|convert|10|C}} (standard temperature conversion)
* {{#invoke:DemoTemplate|convert|10|C}} (standard temperature conversion)
* {{#invoke:DemoTemplate|convert|10–15|C}} (standard temperature range conversion)
* {{#invoke:DemoTemplate|convert|10|-|15|C}} (standard temperature range conversion)


When expressing a temperature ''change'' (e.g., "The temperature ''increased'' by 10&nbsp;°C"), or when ''comparing'' temperatures (e.g., "10 to 15&nbsp;°C ''warmer''"), we cannot use the standard temperature units ({{para||C}}, {{para||F}} and {{para||K}}), which refer to points on the respective scale. Instead, we must use one of the following "units of difference": {{para||C-change}}, {{para||F-change}} and {{para||K-change}}.
When expressing a temperature ''change'' (e.g., "The temperature ''increased'' by 10&nbsp;°C"), or when ''comparing'' temperatures (e.g., "10 to 15&nbsp;°C ''warmer''"), we cannot use the standard temperature units ({{para||C}}, {{para||F}} and {{para||K}}), which refer to points on the respective scale. Instead, we must use one of the following "units of difference": {{para||C-change}}, {{para||F-change}} and {{para||K-change}}.
Line 570: Line 602:


* {{#invoke:DemoTemplate|convert|10|C-change}} increase in temperature
* {{#invoke:DemoTemplate|convert|10|C-change}} increase in temperature
* {{#invoke:DemoTemplate|convert|10–15|C-change}} warmer than normal
* {{#invoke:DemoTemplate|convert|10|-|15|C-change}} warmer than normal


To produce multiple units in the output:
To produce multiple units in the output:
Line 586: Line 618:
* <code><nowiki>{{convert|2|m|ftin}}</nowiki></code> → {{convert|2|m|ftin}}
* <code><nowiki>{{convert|2|m|ftin}}</nowiki></code> → {{convert|2|m|ftin}}
* <code><nowiki>{{convert|2|m|ft in}}</nowiki></code> → {{convert|2|m|ft in}}, using a space, returns the decimal point
* <code><nowiki>{{convert|2|m|ft in}}</nowiki></code> → {{convert|2|m|ft in}}, using a space, returns the decimal point
Default behaviour, for comparison:
Default behavior, for comparison:
* <code><nowiki>{{convert|2|m}}</nowiki></code> → {{convert|2|m}}
* <code><nowiki>{{convert|2|m}}</nowiki></code> → {{convert|2|m}}


Line 614: Line 646:
Note: to return that property value for an ''other'' article, use {{para|qid}}.
Note: to return that property value for an ''other'' article, use {{para|qid}}.


Example for {{Wikidata property link|P2073}}:
Example for {{Wikidata property link|P2073}} of {{Wikidata entity link|{{get QID|Cessna 208 Caravan}}}}:
Note: this example uses {{para|qid|Q1056131}} (testing for {{Wikidata entity link|Q1056131}})
* <code><nowiki>{{convert|input=P2073|qid={{get QID|Cessna 208 Caravan}}|ftin|abbr=on}}</nowiki></code>  &rarr; {{convert|input=P2073|qid={{get QID|Cessna 208 Caravan}}|ftin|abbr=on}}
* <code><nowiki>{{convert|input=P2073|qid=Q1056131|ftin|abbr=on}}</nowiki></code>  &rarr; {{convert|input=P2073|qid=Q1056131|ftin|abbr=on}}
* <code><nowiki>{{convert|input=P2073|qid=Q1056131|km|abbr=on}}</nowiki></code>  &rarr; {{convert|input=P2073|qid=Q1056131|km|abbr=on}}
* <code><nowiki>{{convert|input=P2073|qid=Q1056131|km|abbr=on}}</nowiki></code>  &rarr; {{convert|input=P2073|qid=Q1056131|km|abbr=on}}
* <code><nowiki>{{convert|input=P2073|qid=Q1056131|km|abbr=on|disp=out}}</nowiki></code>  &rarr; {{convert|input=P2073|qid=Q1056131|km|abbr=on|disp=out}}
* <code><nowiki>{{convert|input=P2073|qid=Q1056131|km|abbr=on|disp=out}}</nowiki></code>  &rarr; {{convert|input=P2073|qid=Q1056131|km|abbr=on|disp=out}}
Line 652: Line 683:
"type": "string",
"type": "string",
"example": "km",
"example": "km",
"required": true
"required": true,
"suggestedvalues": [
"km2",
"m2",
"cm2",
"mm2",
"ha",
"sqmi",
"acre",
"sqyd",
"sqft",
"sqin",
"km",
"m",
"cm",
"mm",
"mi",
"yd",
"ft",
"in",
"kg",
"g",
"mg",
"lb",
"oz",
"m/s",
"km/h",
"mph",
"K",
"C",
"F",
"m3",
"cm3",
"mm3",
"L",
"mL",
"cuft",
"cuin",
"U.S.gal",
"U.S.oz",
"psi",
"mpgU.S.",
"$/lb",
"$/kg"
]
},
},
"3": {
"3": {
Line 659: Line 734:
"type": "string",
"type": "string",
"example": "mi nmi",
"example": "mi nmi",
"suggested": true
"suggested": true,
"suggestedvalues": [
"km2",
"m2",
"cm2",
"mm2",
"ha",
"sqmi",
"acre",
"sqyd",
"sqft",
"sqin",
"km",
"m",
"cm",
"mm",
"mi",
"yd",
"ft",
"in",
"kg",
"g",
"mg",
"lb",
"oz",
"m/s",
"km/h",
"mph",
"K",
"C",
"F",
"m3",
"cm3",
"mm3",
"L",
"mL",
"cuft",
"cuin",
"U.S.gal",
"U.S.oz",
"psi",
"mpgU.S.",
"$/lb",
"$/kg"
]
},
},
"4": {
"4": {
Line 668: Line 787:
"lk": {
"lk": {
"label": "Link units",
"label": "Link units",
"description": "Indication of what units to apply wikilinks to. Use “on” for all, “in” for the input unit, “out” for the output units, or “off” for none of the units.",
"description": "Indication of what units to apply wikilinks to. Use “on” for all, “in” for the input unit, “out” for the output units, or “off” for none of the units. For more fine-grained control over which units to link, use the template multiple times.",
"default": "off",
"default": "off",
"type": "string",
"type": "string",
"example": "on"
"example": "on",
"suggestedvalues": [
"in",
"out",
"on",
"off"
]
},
},
"abbr": {
"abbr": {
Line 679: Line 804:
"type": "string",
"type": "string",
"example": "on, unit, in, out, off",
"example": "on, unit, in, out, off",
"suggested": true
"suggested": true,
"suggestedvalues": [
"in",
"off",
"none",
"on",
"out",
"unit",
"values",
"~"
]
},
},
"sp": {
"sp": {
Line 692: Line 827:
"type": "unbalanced-wikitext",
"type": "unbalanced-wikitext",
"example": "on",
"example": "on",
"default": "off"
"default": "off",
"suggestedvalues": [
"mid",
"on",
"pre",
"ri0",
"ri1",
"ri2",
"ri3",
"off"
]
},
},
"disp": {
"disp": {
Line 698: Line 843:
"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.",
"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.",
"type": "string",
"type": "string",
"example": "b"
"example": "b",
"suggestedvalues": [
"b",
"sqbr",
"br",
"comma",
"or",
"number",
"output number only",
"out",
"output only",
"preunit",
"table",
"tablecen",
"unit",
"unit2",
"x"
]
},
},
"order": {
"order": {
Line 704: Line 866:
"description": "“flip” returns converted value first, input value second.",
"description": "“flip” returns converted value first, input value second.",
"type": "string",
"type": "string",
"example": "flip"
"example": "flip",
"suggestedvalues": [
"flip",
"out"
]
},
},
"sigfig": {
"sigfig": {
Line 720: Line 886:
"description": "Sets or suppresses the use of thousands separators in the numbers. “off”: no separator; “gaps”: use space instead of comma as thousands separator; “5”: only add thousands separator when the integral part of the number uses 5 positions or more (10,000 or more; if using comma as thousands separator, 1234 would produce '1234', 12345 would produce '12,345').",
"description": "Sets or suppresses the use of thousands separators in the numbers. “off”: no separator; “gaps”: use space instead of comma as thousands separator; “5”: only add thousands separator when the integral part of the number uses 5 positions or more (10,000 or more; if using comma as thousands separator, 1234 would produce '1234', 12345 would produce '12,345').",
"default": "on",
"default": "on",
"type": "string",
"type": "boolean",
"example": "off"
"example": "off"
},
},
Line 726: Line 892:
"label": "Sort key",
"label": "Sort key",
"description": "“on” generates a hidden sort key",
"description": "“on” generates a hidden sort key",
"type": "string",
"type": "boolean",
"example": "on"
"example": "on"
},
},
Line 733: Line 899:
"description": "If used, spells input or input and output numbers in words, optionally capitalizing the first",
"description": "If used, spells input or input and output numbers in words, optionally capitalizing the first",
"example": "'in', 'In', 'on', or 'On'",
"example": "'in', 'In', 'on', or 'On'",
"type": "string"
"type": "string",
"suggestedvalues": [
"in",
"In",
"on",
"On"
]
},
},
"sing": {
"sing": {
"type": "string",
"type": "boolean",
"deprecated": "use adj=",
"deprecated": "use adj=",
"label": "Singular?",
"label": "Singular?",
Line 758: Line 930:
"example": "{{convert|input=P2046}} (P2046=area)",
"example": "{{convert|input=P2046}} (P2046=area)",
"type": "string"
"type": "string"
},
"altitude_ft": {
"label": "Mach altitude (ft)",
"description": "Mach (speed) depends on altitide",
"type": "number",
"suggestedvalues": [
"10000"
]
},
"altitude_m": {
"label": "Mach altitude (m)",
"description": "Mach (speed) depends on altitude",
"type": "number"
}
}
},
},
"format": "inline"
"format": "inline",
"paramOrder": [
"1",
"2",
"3",
"4",
"lk",
"abbr",
"sp",
"adj",
"disp",
"order",
"sigfig",
"round",
"comma",
"sortable",
"spell",
"sing",
"frac",
"$",
"altitude_ft",
"altitude_m",
"input"
]
}
}
</templatedata>
</templatedata>
Line 780: Line 988:
[[Category:Convert by module documentation| ]]
[[Category:Convert by module documentation| ]]
</noinclude><includeonly>{{Sandbox other||{{#ifeq:{{SUBPAGENAME}}|doc||
</noinclude><includeonly>{{Sandbox other||{{#ifeq:{{SUBPAGENAME}}|doc||
[[Category:Convert templates| ]]
[[Category:Template Convert| ]]
[[Category:Conversion templates]]
[[Category:Conversion templates]]
[[Category:Numbers as words conversion templates]]
[[Category:Numbers as words conversion templates]]
[[Category:Sorting templates]]
[[Category:Sorting templates]]
}}}}</includeonly>
}}}}</includeonly>
Anonymous user