Template:Dist: Difference between revisions

From OniGalore
Jump to navigation Jump to search
(named decimal place param "dec"; added "po" param for showing product only; added meter-inch conversion; added inch to foot-and-inch conversion)
m (added template call in docs for in->ft conversion)
 
(One intermediate revision 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 53: Line 53:
===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}}



Latest revision as of 00:26, 5 November 2024

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, 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

{{Dist|100|cm|in}}
yields
100 cm (39.37 in)

{{Dist|100|in|cm}}
yields
100 in (254 cm)

in <-> m

{{Dist|2|m|in}}
yields
2 m (78.74 in)

{{Dist|21|in|m}}
yields
21 in (0.53 m)

m <-> ft

{{Dist|100|ft|m}}
yields
100 ft (30.48 m)

{{Dist|100|m|ft}}
yields
100 m (328.08 ft)

km <-> mi

{{Dist|100|km|mi}}
yields
100 km (62.14 mi)

{{Dist|100|mi|km}}
yields
100 mi (160.93 km)

in -> ft

Dist also supports a special conversion from inches to feet-and-inches:
{{Dist|21|in|ft}}
yields
21 in (1 ft 9 in)

Precision

An optional "dec" parameter specifies the number of decimal places to provide in the conversion.

{{Dist|100|mi|km|dec=1}}
yields
100 mi (160.9 km)

{{Dist|100|mi|km|dec=0}}
yields
100 mi (161 km)

Display

An optional "po" parameter, when set to "yes", tells the template to only print the converted product.

{{Dist|100|cm|in|po=yes}}
yields
39.37 in