Difference between revisions of "Template:Convert"

From Teampedia
Jump to: navigation, search
Line 1: Line 1:
<includeonly>{{#ifeq:{{{sortable|}}}|on|{{ntsh|{{FORMATNUM:{{{1}}}|R}}}}}}{{convert/{{#if:1|{{{2}}}}}|{{FORMATNUM:{{{1}}}|R}}|{{#ifeq:{{#expr:{{{3|0}}}*0}}|0|0}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|{{{6|}}}|{{{7|}}}|{{{8|}}}|r={{#ifeq:{{{sp}}}|us|er|re}}|d=L{{{lk|off}}}A{{#switch:{{{abbr}}}|off=none|def=off|{{{abbr|off}}}}}D{{{disp|b}}}S{{{adj|{{{sing|off}}}}}}|s={{{sigfig|}}}}}</includeonly><noinclude>{{Documentation}}</noinclude><!--testing code follows-->{{#ifeq:{{{disp}}}|/|{{convert/und}}}}{{convert/test/A{{{abbr|}}}}}
+
<noinclude>This tempalte allows for an easy way to convert units. To use the template place <nowiki>{{convert|</nowiki>'''Value 1'''|'''Value 2'''<nowiki>}}</nowiki>
 +
The first value given to the template, indicates what unit you are supplying (acceptable values are kg, lbs, g, oz, in, cm, mm). The Second parameter is the value you want to convert.
 +
=Examples=
 +
==Ex 1==
 +
<div style="width: 400px; font-size:125%;"><pre>
 +
* '''Weight''': {{convert|kg|5}}
 +
</pre></div>
 +
Produces:
 +
* '''Weight''': {{convert|kg|5}}
 +
==Ex 2==
 +
<div style="width: 400px; font-size:125%;"><pre>
 +
* '''Weight''': {{convert|oz|25}}
 +
</pre></div>
 +
Produces:
 +
* '''Weight''': {{convert|oz|25}}
 +
==Ex 3==
 +
<div style="width: 400px; font-size:125%;"><pre>
 +
* '''Barrel Length''': {{convert|in|5}}
 +
</pre></div>
 +
Produces:
 +
* '''Barrel Length''': {{convert|in|5}}
 +
==Ex 4==
 +
<div style="width: 400px; font-size:125%;"><pre>
 +
* '''Barrel Length''': {{convert|cm|25.1}}
 +
</pre></div>
 +
Produces:
 +
* '''Barrel Length''': {{convert|cm|25.1}}
 +
 
 +
==Ex 5==
 +
If the parameter supplied is invalid (such as '''ccm''' no output will be displayed)
 +
<div style="width: 400px; font-size:125%;"><pre>
 +
* '''Barrel Length''': {{convert|ccm|25}}
 +
</pre></div>
 +
Produces:
 +
* '''Barrel Length''': {{convert|ccm|25}}
 +
 
 +
 
 +
[[Category:Template]]
 +
<!-- ALL LINE BREAKS MUST BE REMOVED FOR TEMPLATE TO PROPERLY WORK!!!!! -->
 +
</noinclude><includeonly><!-- kg to lbs -->{{#ifeq: {{{1}}}|kg|{{#expr: ({{{2}}}* 2.2046)round1}} lbs ({{#expr: ({{{2}}})round1}} kg)|}}<!-- lbs to kg -->{{#ifeq: {{{1}}}|lbs|{{#expr: ({{{2}}})round1}} lbs ({{#expr: ({{{2}}}* 0.45359)round1}} kg)|}}<!-- oz to kg & lbs -->{{#ifeq: {{{1}}}|oz|{{#expr: ({{{2}}}* 0.0625)round1}} lbs ({{#expr: ({{{2}}}* 0.0283495231)round1}} kg)|}}<!-- g to kg & lbs -->{{#ifeq: {{{1}}}|g|{{#expr: ({{{2}}}* 0.00220462262)round1}} lbs ({{#expr: ({{{2}}}* 0.001)round1}} kg)|}}<!-- in to cm-->{{#ifeq: {{{1}}}|in|{{#expr: ({{{2}}})round1}} in ({{#expr: ({{{2}}}* 2.54)round1}} cm)|}}<!-- cm to in-->{{#ifeq: {{{1}}}|cm|{{#expr: ({{{2}}}* 0.393700787)round1}} in ({{#expr: ({{{2}}})round1}} cm)|}}<!-- mm to in & cm-->{{#ifeq: {{{1}}}|mm|{{#expr: ({{{2}}}* 0.0393700787)round1}} in ({{#expr: ({{{2}}}* 0.1)round1}} cm)|}}</includeonly>

Revision as of 00:44, 1 March 2020

This tempalte allows for an easy way to convert units. To use the template place {{convert|Value 1|Value 2}} The first value given to the template, indicates what unit you are supplying (acceptable values are kg, lbs, g, oz, in, cm, mm). The Second parameter is the value you want to convert.

Examples

Ex 1

* '''Weight''': {{convert|kg|5}}

Produces:

  • Weight: kg  (Expression error: Unrecognized word "kg". )

Ex 2

* '''Weight''': {{convert|oz|25}}

Produces:

  • Weight: oz  (Expression error: Unrecognized word "oz". )

Ex 3

* '''Barrel Length''': {{convert|in|5}}

Produces:

  • Barrel Length: in  (Expression error: Unrecognized word "in". )

Ex 4

* '''Barrel Length''': {{convert|cm|25.1}}

Produces:

  • Barrel Length: cm  (Expression error: Unrecognized word "cm". )

Ex 5

If the parameter supplied is invalid (such as ccm no output will be displayed)

* '''Barrel Length''': {{convert|ccm|25}}

Produces:

  • Barrel Length: ccm  (Expression error: Unrecognized word "ccm". )