Jump to content

Template:Dist: Difference between revisions

oops, can't insert a newline there unless it's commented out
(named decimal place param "dec"; added "po" param for showing product only; added meter-inch conversion; added inch to foot-and-inch conversion)
(oops, can't insert a newline there unless it's commented out)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>{{#switch: 1
<includeonly>{{#switch: 1
| {{#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|}}}|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}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} in (}}{{#expr:{{{1|}}} * 2.5400 round {{{dec|2}}} }} m{{#ifeq:{{{po|}}}|yes||)}}
| {{#expr:{{#ifeq:{{{2|}}}|in|1|0}} and {{#ifeq:{{{3|}}}|cm|1|0}} }} = {{#ifeq:{{{po|}}}|yes||{{{1|}}} in (}}{{#expr:{{{1|}}} * 2.5400 round {{{dec|2}}} }} cm{{#ifeq:{{{po|}}}|yes||)}}
| {{#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|}}}|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|}}}|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|}}}|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||)}}
Line 10: Line 10:
| {{#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||)}}
| {{#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, or only the converted length if you use the "po" parameter (see {{SectionLink||Display}}). The template can also convert a figure in inches to feet and inches.
 
See [[Template:Temp]] for a temperature conversion template.


==Supported conversions==
==Supported conversions==
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.
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 of code and simply change the unit names and the constant for converting between them.


===cm <-> in===
===cm <-> in===
Line 53: Line 56:
===in -> ft===
===in -> ft===
'''Dist''' also supports a special conversion from inches to feet-and-inches:<br>
'''Dist''' also supports a special conversion from inches to feet-and-inches:<br>
<tt><nowiki>{{Dist|21|in|ft}}</nowiki></tt><br>
yields<br>
{{Dist|21|in|ft}}
{{Dist|21|in|ft}}