Convert Temperatures

Converts temperatures between Celsius and Fahrenheit. Use 'c' or 'f' as the scale you want to convert to.

function ConvertTemp(num, toScale)
assert(tonumber(num), 'ConvertTemp expects a number.')
assert((toScale == 'c') or (toScale == 'f'),
'ConvertTemp expects c or f as the scale to convert to.')
local outTemp = 0
if toScale == 'c' then
outTemp = Round((5 / 9) * (num - 32))
else
outTemp = Round((9 / 5) * num + 32)
end
return outTemp
end
function Round(num, idp)
assert(tonumber(num), 'Round expects a number.')
local mult = 10 ^ (idp or 0)
if num >= 0 then
return math.floor(num * mult + 0.5) / mult
else
return math.ceil(num * mult - 0.5) / mult
end
end