19,704
edits
 (surprised we didn't make this years ago)  | 
				 (added precision parameter)  | 
				||
| 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}} in)  | | {{#expr:{{#ifeq:{{{2|}}}|cm|1|0}} and {{#ifeq:{{{3|}}}|in|1|0}} }} = {{{1|}}} cm ({{#expr:{{{1|}}} * 0.3937 round {{{4|2}}} }} in)  | ||
| {{#expr:{{#ifeq:{{{2|}}}|in|1|0}} and {{#ifeq:{{{3|}}}|cm|1|0}} }} = {{{1|}}} in ({{#expr:{{{1|}}} * 2.5400}} cm)  | | {{#expr:{{#ifeq:{{{2|}}}|in|1|0}} and {{#ifeq:{{{3|}}}|cm|1|0}} }} = {{{1|}}} in ({{#expr:{{{1|}}} * 2.5400 round {{{4|2}}} }} cm)  | ||
| {{#expr:{{#ifeq:{{{2|}}}|km|1|0}} and {{#ifeq:{{{3|}}}|mi|1|0}} }} = {{{1|}}} km ({{#expr:{{{1|}}} * 0.6214}} mi)  | | {{#expr:{{#ifeq:{{{2|}}}|km|1|0}} and {{#ifeq:{{{3|}}}|mi|1|0}} }} = {{{1|}}} km ({{#expr:{{{1|}}} * 0.6214 round {{{4|2}}} }} mi)  | ||
| {{#expr:{{#ifeq:{{{2|}}}|mi|1|0}} and {{#ifeq:{{{3|}}}|km|1|0}} }} = {{{1|}}} mi ({{#expr:{{{1|}}} * 1.6093}} km)  | | {{#expr:{{#ifeq:{{{2|}}}|mi|1|0}} and {{#ifeq:{{{3|}}}|km|1|0}} }} = {{{1|}}} mi ({{#expr:{{{1|}}} * 1.6093 round {{{4|2}}} }} km)  | ||
| {{#expr:{{#ifeq:{{{2|}}}|ft|1|0}} and {{#ifeq:{{{3|}}}|m|1|0}} }}  = {{{1|}}} ft ({{#expr:{{{1|}}} * 0.3048}} m)  | | {{#expr:{{#ifeq:{{{2|}}}|ft|1|0}} and {{#ifeq:{{{3|}}}|m|1|0}} }}  = {{{1|}}} ft ({{#expr:{{{1|}}} * 0.3048 round {{{4|2}}} }} m)  | ||
| {{#expr:{{#ifeq:{{{2|}}}|m|1|0}}  and {{#ifeq:{{{3|}}}|ft|1|0}} }} = {{{1|}}} m ({{#expr:{{{1|}}} * 3.2808}} ft)  | | {{#expr:{{#ifeq:{{{2|}}}|m|1|0}}  and {{#ifeq:{{{3|}}}|ft|1|0}} }} = {{{1|}}} m ({{#expr:{{{1|}}} * 3.2808 round {{{4|2}}} }} ft)  | ||
| #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==  | |||
Here are all the conversions supported by the template. If you want anything else to be supported, you can add it yourself; the existing code should be easy to follow.  | Here are all the conversions supported by the template. If you want anything else to be supported, you can add it yourself; the existing code should be easy to follow.  | ||
===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 19: | Line 21: | ||
{{Dist|100|in|cm}}  | {{Dist|100|in|cm}}  | ||
===m-ft===  | |||
<tt><nowiki>{{Dist|100|ft|m}}</nowiki></tt><br>  | |||
yields<br>  | |||
{{Dist|100|ft|m}}  | |||
<tt><nowiki>{{Dist|100|m|ft}}</nowiki></tt><br>  | |||
yields<br>  | |||
{{Dist|100|m|ft}}  | |||
===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 27: | Line 39: | ||
{{Dist|100|mi|km}}  | {{Dist|100|mi|km}}  | ||
<tt><nowiki>{{Dist|100|  | ==Precision==  | ||
An optional fourth parameter specifies the number of decimal places to provide in the conversion.  | |||
<tt><nowiki>{{Dist|100|mi|km|1}}</nowiki></tt><br>  | |||
yields<br>  | yields<br>  | ||
{{Dist|100|  | {{Dist|100|mi|km|1}}  | ||
<tt><nowiki>{{Dist|100|  | <tt><nowiki>{{Dist|100|mi|km|0}}</nowiki></tt><br>  | ||
yields<br>  | yields<br>  | ||
{{Dist|100|  | {{Dist|100|mi|km|0}}  | ||
[[Category:Utility templates]]</noinclude>  | [[Category:Utility templates]]</noinclude>  | ||