Template:Temp: Difference between revisions

From OniGalore
Jump to navigation Jump to search
(Created page with "<includeonly>{{#ifeq:{{{2|}}}| C|{{{1}}}° C ({{#expr:({{{1|}}} * 1.8) + {{#ifeq:{{{4|0}}}|0|32|0}} round {{#expr:{{{3|0}}} + 1}} }}° F)|...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>{{#ifeq:{{{2|}}}|
<includeonly>{{#ifeq:{{{2|}}}|
                     C|{{{1}}}&deg; C ({{#expr:({{{1|}}} * 1.8) + {{#ifeq:{{{4|0}}}|0|32|0}} round {{#expr:{{{3|0}}} + 1}} }}&deg; F)|
                     C|{{{1}}}&deg; C ({{#expr:({{{1|}}} * 1.8) + {{#ifeq:{{{4|0}}}|0|32|0}} round {{{3|0}}} }}&deg; F)|
                     {{#ifeq:{{{2|}}}|
                     {{#ifeq:{{{2|}}}|
                             F|{{{1}}}&deg; F ({{#expr:({{{1|}}} - {{#ifeq:{{{4|0}}}|0|32|0}}) / 1.8 round {{#expr:{{{3|0}}} + 1}} }}&deg; C)|
                             F|{{{1}}}&deg; F ({{#expr:({{{1|}}} - {{#ifeq:{{{4|0}}}|0|32|0}}) / 1.8 round {{{3|0}}} }}&deg; C)|
                             '''<span style="color:red">(error from Template:Temp: the unit was not given as 'C' or 'F')'''</span>}} }}</includeonly><noinclude>Call this template to convert a temperature between Celsius and Fahrenheit. Both will be displayed, with the unit you supplied coming first.
                             '''<span style="color:red">(error from Template:Temp: the unit was not given as 'C' or 'F')</span>'''}} }}</includeonly><noinclude>Call this template to convert a temperature between Celsius and Fahrenheit. Both will be displayed, with the unit you supplied coming first.


==Simplest use case==
==Simplest use case==
Line 23: Line 23:
{{Temp|99|C|5}}
{{Temp|99|C|5}}


Note that the output only has one decimal place despite asking for five; that's because it will omit zeroes. For that reason, <tt><nowiki>{{Temp|100|C|5}}</nowiki></tt> will simply return 212° F.
Note that the output only has one decimal place despite the template call asking for five; that's because the answer was 210.20000, but the template won't display zero places. For that reason, <tt><nowiki>{{Temp|100|C|5}}</nowiki></tt> will simply return {{Temp|100|C|5}}.


==Relative change==
==Relative change==
Line 30: Line 30:
<tt><nowiki>{{Temp|9|C|0|r}}</nowiki></tt><br>
<tt><nowiki>{{Temp|9|C|0|r}}</nowiki></tt><br>
yields<br>
yields<br>
{{Temp|9|F|0|r}}
{{Temp|9|C|0|r}}


[[Category:Utility templates]]</noinclude>
[[Category:Utility templates]]</noinclude>

Latest revision as of 01:50, 24 April 2023

Call this template to convert a temperature between Celsius and Fahrenheit. Both will be displayed, with the unit you supplied coming first.

Simplest use case

To convert degrees between C and F, just supply a number and the unit it's in:

{{Temp|100|C}}
yields
100° C (212° F)

{{Temp|212|F}}
yields
212° F (100° C)

Decimal precision

Supply a third parameter to ask for a number of places after the decimal:

{{Temp|99|C|5}}
yields
99° C (210.2° F)

Note that the output only has one decimal place despite the template call asking for five; that's because the answer was 210.20000, but the template won't display zero places. For that reason, {{Temp|100|C|5}} will simply return 100° C (212° F).

Relative change

If you are converting a relative change in temperature, not an absolute temperature, supply "r" as the fourth parameter (though the way the logic in the template currently works, you can actually type anything for a fourth parameter and it will do the same):

{{Temp|9|C|0|r}}
yields
9° C (16° F)