19,499
edits
(added precision parameter) |
(named decimal place param "dec"; added "po" param for showing product only; added meter-inch conversion; added inch to foot-and-inch conversion) |
||
Line 1: | Line 1: | ||
<includeonly>{{#switch: 1 | <includeonly>{{#switch: 1 | ||
| {{#expr:{{#ifeq:{{{2|}}}|cm|1|0}} and {{#ifeq:{{{3|}}}|in|1|0}} }} = {{{1|}}} cm ({{#expr:{{{1|}}} * 0.3937 round {{{ | | {{#expr:{{#ifeq:{{{2|}}}|cm|1|0}} and {{#ifeq:{{{3|}}}|in|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} cm (}}{{#expr:{{{1|}}} * 0.3937 round {{{dec|2}}} }} in{{#ifeq:{{{po|}}}|yes||)}} | ||
| {{#expr:{{#ifeq:{{{2|}}}|in|1|0}} and {{#ifeq:{{{3|}}}|cm|1|0}} }} = {{{1|}}} in ({{#expr:{{{1|}}} * 2.5400 round {{{ | | {{#expr:{{#ifeq:{{{2|}}}|in|1|0}} and {{#ifeq:{{{3|}}}|cm|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} in (}}{{#expr:{{{1|}}} * 2.5400 round {{{dec|2}}} }} m{{#ifeq:{{{po|}}}|yes||)}} | ||
| {{#expr:{{#ifeq:{{{2|}}}|km|1|0}} and {{#ifeq:{{{3|}}}|mi|1|0}} }} = {{{1|}}} km ({{#expr:{{{1|}}} * 0.6214 round {{{ | | {{#expr:{{#ifeq:{{{2|}}}|m|1|0}} and {{#ifeq:{{{3|}}}|in|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} m (}}{{#expr:{{{1|}}} * 39.370 round {{{dec|2}}} }} in{{#ifeq:{{{po|}}}|yes||)}} | ||
| {{#expr:{{#ifeq:{{{2|}}}|mi|1|0}} and {{#ifeq:{{{3|}}}|km|1|0}} }} = {{{1|}}} mi ({{#expr:{{{1|}}} * 1.6093 round {{{ | | {{#expr:{{#ifeq:{{{2|}}}|in|1|0}} and {{#ifeq:{{{3|}}}|m|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} in (}}{{#expr:{{{1|}}} * 0.0254 round {{{dec|2}}} }} m{{#ifeq:{{{po|}}}|yes||)}} | ||
| {{#expr:{{#ifeq:{{{2|}}}|ft|1|0}} and {{#ifeq:{{{3|}}}|m|1|0}} }} = {{{1|}}} ft ({{#expr:{{{1|}}} * 0.3048 round {{{ | | {{#expr:{{#ifeq:{{{2|}}}|km|1|0}} and {{#ifeq:{{{3|}}}|mi|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} km (}}{{#expr:{{{1|}}} * 0.6214 round {{{dec|2}}} }} mi{{#ifeq:{{{po|}}}|yes||)}} | ||
| {{#expr:{{#ifeq:{{{2|}}}|m|1|0}} and {{#ifeq:{{{3|}}}|ft|1|0}} }} = {{{1|}}} m ({{#expr:{{{1|}}} * 3.2808 round {{{ | | {{#expr:{{#ifeq:{{{2|}}}|mi|1|0}} and {{#ifeq:{{{3|}}}|km|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} mi (}}{{#expr:{{{1|}}} * 1.6093 round {{{dec|2}}} }} km{{#ifeq:{{{po|}}}|yes||)}} | ||
| {{#expr:{{#ifeq:{{{2|}}}|ft|1|0}} and {{#ifeq:{{{3|}}}|m|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} ft (}}{{#expr:{{{1|}}} * 0.3048 round {{{dec|2}}} }} m{{#ifeq:{{{po|}}}|yes||)}} | |||
| {{#expr:{{#ifeq:{{{2|}}}|m|1|0}} and {{#ifeq:{{{3|}}}|ft|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} m (}}{{#expr:{{{1|}}} * 3.2808 round {{{dec|2}}} }} ft{{#ifeq:{{{po|}}}|yes||)}} | |||
| {{#expr:{{#ifeq:{{{2|}}}|in|1|0}} and {{#ifeq:{{{3|}}}|ft|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} in (}}{{#expr:trunc ({{{1|}}} / 12.000) }} ft {{#expr:{{{1|}}} mod 12}} in{{#ifeq:{{{po|}}}|yes||)}} | |||
| #default = '''<span style="color:red">(error from Template:Dist: unsupported conversion)</span>''' | | #default = '''<span style="color:red">(error from Template:Dist: unsupported conversion)</span>''' | ||
}}</includeonly><noinclude>Call this template to convert between metric and imperial units of length. Both the original and converted length will be displayed, with the unit you supplied coming first. | }}</includeonly><noinclude>Call this template to convert between metric and imperial units of length. Both the original and converted length will be displayed, with the unit you supplied coming first. | ||
==Supported conversions== | ==Supported conversions== | ||
Here are all the conversions supported by the template. If you want anything else to be supported, | Here are all the conversions supported by the template. If you want anything else to be supported, it's fairly easy to add new conversions: copy a line and change the unit names and the constant for converting between them. | ||
===cm-in=== | ===cm <-> in=== | ||
<tt><nowiki>{{Dist|100|cm|in}}</nowiki></tt><br> | <tt><nowiki>{{Dist|100|cm|in}}</nowiki></tt><br> | ||
yields<br> | yields<br> | ||
Line 21: | Line 24: | ||
{{Dist|100|in|cm}} | {{Dist|100|in|cm}} | ||
===m-ft=== | ===in <-> m=== | ||
<tt><nowiki>{{Dist|2|m|in}}</nowiki></tt><br> | |||
yields<br> | |||
{{Dist|2|m|in}} | |||
<tt><nowiki>{{Dist|21|in|m}}</nowiki></tt><br> | |||
yields<br> | |||
{{Dist|21|in|m}} | |||
===m <-> ft=== | |||
<tt><nowiki>{{Dist|100|ft|m}}</nowiki></tt><br> | <tt><nowiki>{{Dist|100|ft|m}}</nowiki></tt><br> | ||
yields<br> | yields<br> | ||
Line 30: | Line 42: | ||
{{Dist|100|m|ft}} | {{Dist|100|m|ft}} | ||
===km-mi=== | ===km <-> mi=== | ||
<tt><nowiki>{{Dist|100|km|mi}}</nowiki></tt><br> | <tt><nowiki>{{Dist|100|km|mi}}</nowiki></tt><br> | ||
yields<br> | yields<br> | ||
Line 38: | Line 50: | ||
yields<br> | yields<br> | ||
{{Dist|100|mi|km}} | {{Dist|100|mi|km}} | ||
===in -> ft=== | |||
'''Dist''' also supports a special conversion from inches to feet-and-inches:<br> | |||
{{Dist|21|in|ft}} | |||
==Precision== | ==Precision== | ||
An optional | An optional "dec" parameter specifies the number of decimal places to provide in the conversion. | ||
<tt><nowiki>{{Dist|100|mi|km|dec=1}}</nowiki></tt><br> | |||
yields<br> | |||
{{Dist|100|mi|km|dec=1}} | |||
<tt><nowiki>{{Dist|100|mi|km| | <tt><nowiki>{{Dist|100|mi|km|dec=0}}</nowiki></tt><br> | ||
yields<br> | yields<br> | ||
{{Dist|100|mi|km| | {{Dist|100|mi|km|dec=0}} | ||
==Display== | |||
An optional "po" parameter, when set to "yes", tells the template to only print the converted product. | |||
<tt><nowiki>{{Dist|100| | <tt><nowiki>{{Dist|100|cm|in|po=yes}}</nowiki></tt><br> | ||
yields<br> | yields<br> | ||
{{Dist|100| | {{Dist|100|cm|in|po=yes}} | ||
[[Category:Utility templates]]</noinclude> | [[Category:Utility templates]]</noinclude> |