మూస:Convert/doc: కూర్పుల మధ్య తేడాలు
Content deleted Content added
చి cleanup |
code |
||
పంక్తి 1:
{{documentation subpage}}<!-- for stats: 673940 tc's on 2014-09-05 -->
{{#ifeq:{{FULLPAGENAME}}|Template:Convert|{{high-risk|680.000}}}}
{{Transwiki guide|text=See [[Template:Convert/Transwiki guide|'''how to copy this template''']] for information on copying this template and modifying it for use on another wiki.}}
{{Lua|Module:Convert}}
'''Template {{tl|convert}}''' ''calculates'' measurements from one
:<code><nowiki>{{convert|2|km|mi}}</nowiki></code>
:<code><nowiki>{{convert|7|mi|km}}</nowiki></code>
The available '''units''' are listed [[#Units|below]].
Multiple '''formatting''' and calculation options are listed below.
{{hatnote|See also [[Help:Convert]] for more complete information}}
==Unit name or symbol (abbreviation): ''1 pound'' or ''1 lb''?==
The "abbreviation" is actually the "symbol".
{{para|abbr|on}} will produce the symbol of the unit, instead of its name:
:<code><nowiki>{{convert|1|lb|kg}}</nowiki></code> → {{convert|1|lb|kg}} <small>(To compare, default)</small>
:<code><nowiki>{{convert|1|lb|kg|abbr=on}}</nowiki></code> → {{convert|1|lb|kg|abbr=on}}
==Adjective: ''a 10-mile distance''==
Use {{para|adj|on}} to produce the
:<code><nowiki>A {{convert|10|mi|km|adj=on}} distance</nowiki></code> → A {{convert|10|mi|km|adj=on}} distance. - Adjective
==
===Default rounding===
:By
{| class="wikitable"
Line 82 ⟶ 35:
|'''Input'''||'''Displays as'''||'''Note'''
|-
|
|-
|
|-
|
|-
|
|-
|
|-
|
|-
|
|}<!--NOTE: rows require "nowiki", using {{ disappears. -->
''Convert'' supports four types of rounding:
===Round to a given precision: ''use
Specify the desired precision with the
===Round to a given number of significant figures: ''use {{para|sigfig|}}''===
To specify the output number to be with ''n'' significant figures use {{para|sigfig|<number>}}:
* <
*
*
*
* <nowiki>{{convert|1200|ft|m|sigfig=1}}</nowiki> → {{convert|1200|ft|m|sigfig=1}}
Setting {{para|sigfig|<=0}} is meaningless
* <nowiki>{{convert|1200|ft|m|sigfig=0}}</nowiki> → {{convert|1200|ft|m|sigfig=0}}
===Round to a multiple of 5: ''15'', ''20'', ''25'', ...===
Using {{para|round|5}} rounds the outcome to a multiple of 5.
Similar: using {{para|round|25}} rounds the outcome to a multiple of 25.
:<small>To compare:</small> <code><nowiki>{{convert|10|m|ft|sigfig=4}}</nowiki></code> → {{convert|10|m|ft|sigfig=4}}
In a range, one can round ''each value'' individually to the default. Use {{para|round|each}}:
===
Specify the desired ''denominator'' using {{para|frac|<some positive integer>}}. ([[Fraction (mathematics)|Denominator]] is the below-the-slash number, for example the 3 in {{frac|1|3}}).
:<code><nowiki>{{convert|6|cm|in|frac=100}}</nowiki></code> → {{convert|6|cm|in|frac=100}}
==={{anchor|Rounding temperatures}}Rounding temperatures
In temperatures, the conversion will be rounded either to precision comparable to that of the input value or to that which would give three significant figures when expressed in kelvins, whichever is more precise.
:<code><nowiki>{{convert|10|C|F K}}</nowiki></code> → {{convert|10|C|F K}}
''Note''
:For a temperature ''difference'', like to convert "A rise of 20 °C", use {{para|C-change|20}} &tc.
:<code><nowiki>{{convert|20|C-change|F-change K-change}}</nowiki></code> → A rise of {{convert|20|C-change|F-change K-change}}
:<small>To compare: "A temperature of 20 °C" would yield: A temperature of {{convert|20|C|F K}}</small>
==Into multiple units: ''{{convert|10|C|F K}}''==
Separate the multiple output units by a space:
==Ranges of values==
===A range: ''6 to 17 kg (13 to 37 lb)''===
Range indicators are entered as the second parameter (between the values). Range separators can be:<br />
{{Convert/doc/range separator list}}
===Multiple dimensions: ''
:<code><nowiki>{{convert|6|by|12|ft|m}}</nowiki></code> → {{convert|6|by|12|ft|m}}
This is the correct way in science, using <code>|x|</code> and {{para|abbr|on}}
:<code><nowiki>{{convert|6|x|12|m|ft|abbr=on}}</nowiki></code> → {{convert|6|x|12|m|ft|abbr=on}}
===About ''feet, inch'' in ranges and multiples===
While it is possible to enter feet, inch in a simple conversion, this is not possible for ranges:
* <code><nowiki>{{convert|1|ft|3
* <code><nowiki>{{convert|1|ft|3|in|x|3|ft|5|in|mm}}</nowiki></code> → {{convert|1|ft|3|in|x|3|ft|5|in|mm}}
==Words==
===Spell out numbers: ''ten miles''===
To write a number in words, use {{para|spell|in}}:
To spell out both in and out values, use {{para|spell|on}}:
To make first letter a capital, use {{para|spell|In}}, {{para|spell|On}}
Remember that the spelling of the units (ft, m) is independently set by {{para|abbr|}}. To the extreme:
===
Default spelling of units is en-UK. To show en-US spelling, use {{para|sp|us}}:
:<code><nowiki>{{convert|1|m|ft}}</nowiki></code> → {{convert|1|m|ft}} -- ''default''
===Extra words: ''4 planted acres'' ===
:''Incomplete section''
:<code><nowiki>{{convert|4|acre||adj=pre|planted}}</nowiki></code> → {{convert|4|acre||adj=pre|planted}}
===Extra adjective words: ''A {{convert|10|ft|ft|adj=mid|-long|disp=out|order=flip}} corridor''===
:<code><nowiki>{{convert|4|ft|m|adj=mid|-long}}</nowiki></code> → {{convert|10|ft|m|adj=mid|-long}}
===Grammatical construction: ''The 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons'' ===
This example is from article [[Fort McHenry#19th_Century|Fort McHenry]]:
{{quotation|The American defenders had 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons.}}
This formatted result is not possible straightforward by using {{tlf|convert}}. However, it can be made in three steps.
:'''Step 1:''' Enter the input numbers and units in {{tlf|convert}} just to get the calculated output:
:*<code><nowiki>had {{convert|18 |, |24 |, |32 |lb |kg |0 }} cannons</nowiki></code>
::→ had {{convert|18 |, |24 |, |32 |lb |kg |0 }} cannons
:The core conversion should look good now. You can save this (or preview).
:'''Step 2:''' We need the resulting text in plain code in the page, not as a {{tlf|convert|...}} template.
:For this, '''add <code>subst:</code> to the template name''' (for 'substitute') :
:*<code><nowiki>had {{</nowiki>{{purple|'''subst:'''}}<nowiki>convert|18 |, |24 |, |32 |lb |kg |0 }} cannons</nowiki></code>
:As a check: the preview result should show the conversion correct, with the numbers still right.
:'''Now save this'''.
::→ had 18, 24, 32 pounds (8, 11, 15 kg) cannons
:'''Step 3:''' When opening the edit screen again, you'll see that the text is there in code. The template {{tlf|convert|...}} itself has disappeared. You can change the text as needed. The edit screen text is:
::<code><nowiki>had 18,&nbsp;24,&nbsp;32 pounds (8,&nbsp;11,&nbsp;15&nbsp;kg) cannons</nowiki></code>
:You can edit this text to add the grammar:
:*<code>had 18{{red|-}},{{red|_}}24{{red|-_and_}}32{{red|-}}pound{{red|er}} (8,&nbsp;11{{red|_and_}}15&nbsp;kg) cannons </code>
:After saving your edit, it shows:
::→ "had 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons".
== Numbers ==
=== Using SI prefixes: ''gigameter (Gm), micrometer (μm)'' ===
{{Sidebar metric prefixes (small)}}
Units can have
To illustrate, these are trivial calculations (from meter to meter),
* {{convert|12|Gm|m|abbr=on}}
* {{convert|12|μm|m|abbr=on}}
The prefix can be added before
* <code><nowiki>{{convert|12|Gm|mi|abbr=on}}</nowiki></code>
* <code>Mm</code>: {{convert|12|Mm|mi|abbr=on}}
* <code>km</code>: {{convert|12|km|ft|abbr=on}}
* <code>mm</code>: {{convert|12|mm|in|abbr=on}}
* <code>
* <code>um</code>: {{convert|12|um|mm|abbr=on}} (letter "u" can be used for "
The prefix can be used in the output unit:
* <code><nowiki>{{convert|12000|mi||Mm|abbr=on}}</nowiki></code>
* <code><nowiki>{{convert|12|in|μm|abbr=on}}</nowiki></code>
* <code><nowiki>{{convert|12|μm|μin|abbr=on}}</nowiki></code> → {{convert|12|μm|μin|abbr=on}}
:{{further|Help:Convert units#SI prefixes}}
===Input with fractions: ''{{convert|1+1/2|in|mm|1}}''===
The number to convert can be written in fractions
Also the fraction slash (<code>⁄</code>) is accepted:
:<code><nowiki>{{convert|1⁄2|in|mm|1}}</nowiki><code> → {{convert|1⁄2|in|mm|1}}
With integers, use a <code>+</code> sign
:<code><nowiki>{{convert|2+1⁄2|in|mm|1}}</nowiki><code> → {{convert|2+1⁄2|in|mm|1}}
When negative, use a hyphen <code>-</code> and repeat it:
:<code><nowiki>{{convert|-2-1⁄2|in|mm|1}}</nowiki><code> → {{convert|-2-1⁄2|in|mm|1}}
:<code><nowiki>{{convert|2-1⁄2|in|mm|1}}</nowiki><code> → {{convert|2-1⁄2|in|mm|1}} Note: this is read as a range
:<code><nowiki>{{convert|-2+1⁄2|in|mm|1}}</nowiki><code> → {{convert|-2+1⁄2|in|mm|1}} {{nay}} Should be a number, not an expression (do not require a calculation)
===Input in engineering notation: ''7 × 10<sup>6</sup> m''===
[[Engineering notation|Engineering number notations]] like ''7{{smallcaps|E}}6'' (for 7 × 10<sup>6</sup>) are to be entered as a prefix <code>e''n''</code> to the unit:
:<code><nowiki>{{convert|7|e6m}}</nowiki></code> → {{convert|7|e6m}}
Any standard unit (not a combination, multiple, or built-in) can have a prefix:
:<code>e3</code> (thousand), <code>e6</code> (million), <code>e9</code> (billion), <code>e12</code> (trillion), <code>e15</code> (quadrillion).
===Output with horizontal fraction bar in: ''{{sfrac|1|2}} inch'' ===
<!-- techinical restriction: TOC does not show the example horizontal bar intended here; rephrased section title-->
Using a double slash (<code>//</code>) returns a horizontal bar fraction:
* <code><nowiki>{{convert|1//2|in|mm|1}}</nowiki></code> → {{convert|1//2|in|mm|1}}
* <code><nowiki>{{convert|2+1//2|in|mm|1}}</nowiki></code> → {{convert|2+1//2|in|mm|1}}
== Output manipulation ==
===Brackets and separators: ''10 m [33 ft]''===
Punctuation that distinguishes the two measurements is set by {{para|disp|}}.<br />
Options are: <code>b</code> <small>(the default)</small>, <code>sqbr</code>, <code>comma</code>, <code>or</code>, <code>br</code>, <code>x{{!}}
:<code><nowiki>{{convert|10|m|ft|disp=or}}</nowiki></code> → {{convert|10|m|ft|disp=or}}
Setting {{para|disp|br}} will force a new line (<code><br
:<code><nowiki>{{convert|10|m|ft|disp=br}}</nowiki></code> → {{convert|10|m|ft|disp=br}}
Setting {{para|disp|x{{!}}...}} allows any text as separator:
:<code><nowiki>{{convert|10|m|ft|disp=x|_MyText_}}</nowiki></code> → {{convert|10|m|ft|disp=x|_MyText_}} -- <small>(To display spaces, use <code>&nbsp;</code>)</small>
===Flipping (reordering) the two measurements: ''{{convert|1|mi|m|order=flip|sigfig=5|abbr=off}}'' ===
Setting {{para|order|flip}} will flip (swap) the two measurements:
:<code><nowiki>{{convert|1|mi|m|order=flip}}</nowiki></code> When converting to multiple units, the effect is:
=== Displaying parts of the result: ''{{convert|2|cuyd|m3|abbr=values}}''===
Line 392 ⟶ 247:
! Convert !! Output !! Description
|-
| <code><nowiki>{{convert|2|cuyd|m3}}</nowiki></code> || {{convert|2|cuyd|m3}} || Default, to compare
|-
| <code><nowiki>{{convert|2|cuyd|m3|abbr=values}}</nowiki></code> || {{convert|2|cuyd|m3|abbr=values}} || Input and output numbers
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit}} || Input unit
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit|adj=on}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit|adj=on}} || Input unit, adjective (hyphenated)
|-
| <code><nowiki>{{convert|2|cuyd|cuyd|0|disp=out|abbr=off}}</nowiki></code> || {{convert|2|cuyd|cuyd|0|disp=out|abbr=off}} || Input (''workaround''
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit2}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit2}} || Output unit (symbol)
Line 413 ⟶ 261:
| <code><nowiki>{{convert|2|cuyd|m3|disp=unit2|abbr=off}}</nowiki></code> || {{convert|2|cuyd|m3|disp=unit2|abbr=off}} || Output unit (name)
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=number}}</nowiki></code> || {{convert|2|cuyd|m3|disp=number}} || Output value
|-
| <code><nowiki>{{convert|2|cuyd|m3|disp=out}}</nowiki></code> || {{convert|2|cuyd|m3|disp=out}} || Output value and unit
|-
| <code><nowiki>{{convert|2|cuyd|m3|abbr=off|disp=out}}</nowiki></code> || {{convert|2|cuyd|m3|abbr=off|disp=out}} || Output value and unit
|}
==
For the [[Help:Table/Manual tables|wikitable]] structure, there are two options: split over columns and make the table sortable.
=== Show numbers only in columns in a table ===
Using {convert} in a table cell, with {{para|disp|table}} splits the result over two columns:
:<code><nowiki>{{convert|10|m|ft|disp=table}}</nowiki></code>
{{para|disp|tablecen}} does the same, and also centers the text:
:<code><nowiki>{{convert|20|m|ft|disp=tablecen}}</nowiki></code>
The units are added as a column header:
Line 467 ⟶ 293:
|}
=== Sorting ===
:Use both {{para|disp|table}} {{para|sortable|on}} to produce table columns (pipe symbols), with sortable table column. As of January 2013, only the first (lefthand) column will sort (improvements pending).
:<nowiki>{{convert|10|m|ft|disp=table|sortable=on}}</nowiki> →
<code>{{nowrap|{{convert|10|m|ft|disp=table|sortable=on}}}}</code>
:This shows the hidden numerical sortkey:
<code>align="right"|<span style="display:none">7001100000000000000</span>10 |align="right"|33</code>
:{| class="wikitable sortable"
! m
! ft
|-
| {{convert|15+3/4|m|ft|disp=table|sortable=on}}
|-
| {{convert|15.5|m|ft|disp=table|sortable=on}}
|-
| {{convert|16.0|m|ft|disp=table|sortable=on}}
|-
| {{convert|16|m|ft|disp=table|sortable=on}}
|}
==Units==
{{selfref|See also: complete [[Template:Convert/list of units|Convert/list of units]]}}
<div style="height: 400px; overflow: auto; padding: 3px; border: 1px solid #aaa;">
{{Convert/list of units}}
</div>
==Parameter list==
Line 569 ⟶ 324:
==Deprecated options==
Deprecated options should not be used. There is no guarantee that they will be supported in the future.
<!-- see for example [[Template_talk:Convert/Archive_September_2014#Next_grand_step:_.7Bconvert.7D_3.0]] -->
* {{!xt|1=disp=slash}}, {{!xt|1=disp=s}}, {{!xt|1=disp=/}} are deprecated. Use {{xt|1=disp=or}} instead
* {{!xt|1=disp=flip}}, {{!xt|1=adj=flip}} are deprecated. Use {{xt|1=order=flip}} instead
* {{!xt|1=disp=flip5}} is deprecated. Use {{xt|1=order=flip}} {{xt|1={{!}}round=5}} instead
* {{!xt|1=disp=5}}, {{!xt|1=near=5}}, is deprecated. Use {{xt|1=round=5}} instead
* {{!xt|1=abbr=comma}} is deprecated. Use {{xt|1=adj=nocomma}} instead
* {{!xt|1=disp=2}} is deprecated. Use {{xt|1=disp=output only}} instead
* {{!xt|1=disp=u2}} is deprecated. Use {{xt|1=disp=unit2}} instead
* {{!xt|1=abbr=mos}} is deprecated (not [[MOS:UNITS|MOS]]). Use range separator {{xt|<nowiki>|by|</nowiki>}} ''or'' {{xt|<nowiki>|x|</nowiki>}} instead
* Range separator {{!xt|<nowiki>|xx|</nowiki>}} is deprecated (not [[MOS:UNITS|MOS]]). Use {{xt|<nowiki>|x|</nowiki>}} instead
* Range separator {{!xt|<nowiki>|*|</nowiki>}} is deprecated (not [[MOS:UNITS|MOS]]). Use {{xt|<nowiki>|x|</nowiki>}} instead
* Range separator {{!xt|<nowiki>|to-|</nowiki>}} is deprecated. Use {{xt|<nowiki>|to(-)|</nowiki>}} instead
==TemplateData==
{{TemplateDataHeader}}
<templatedata>{
"description": "Converts measurements to other units.",
"params": {
"description": "the value to convert",
"type": "number"
},
"label": "from unit",
"description": "",
},
"3": {
"description": "",
"type": "string/line"
},
"4": {
"label": "precision or suffix",
"description": "significant digits after decimal dot or, if negative, exponent of ten",
},
"lk": {
"label": "link units",
"description": "“on” all, “in” input, “out” output or “off” no units",
"default": "off",
},
"sp": {
"label": "spelling",
"description": "“us” display U.S. spelling of unit names",
"type": "string/line"
},
"label": "adjective",
"description": "adjective form (singular unit name appended by hyphen) “on” or “mid” to put conversion at end",
},
"disp": {
"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",
},
"order": {
"description": "“flip” returns converted value first, input value second.",
"type": "string/line"
},
"sigfig": {
"label": "significant figures",
"description": "number that sets the number of significant figures",
"description": "“5” rounds the output number to nearest multiple of 5, “25” to nearest multiple of 25, “each” rounds each number in a range",
},
"sortable": {
"label": "sort key",
"description": "“on” generates a hidden sort key",
"type": "string/line"
}
}}</templatedata>
<!--
==Glossary==
:''to be added''
-->
==See also==
* [[Template:Convert/old]] — Version as used until December 2013
* [[Template:Convert/units not supported]]
* [[:Category:Convert error categories]]
{{Math templates|conversion}}<noinclude>
[[Category:Convert by module documentation| ]]
</noinclude><includeonly>
[[Category:Convert templates| ]]
[[Category:Conversion templates]]
[[Category:Numbers as words conversion templates]]
</includeonly>
|