Module:Weather box/row/sandbox: Difference between revisions

Content deleted Content added
try limiting precision to 2; more than 2 is pointless
modify convert procedure to limit the output precision for some results
Line 51:
}, Value)
end,
converts = {
setConvert = function (self, invalue, factor)
in2cm = { factor = 2.54 },
-- Use method from [[Module:Convert]] to determine precision.
in2mm = { factor = 25.4 },
local outnum = invalue.number * factor
cm2in = { factor = 1/2.54, p2max = 1 },
mm2in = { factor = 1/25.4, p2max = 0 },
},
setConvert = function (self, invalue, factorunits)
-- Use method modified from [[Module:Convert]] to determine precision.
local convert = self.converts[units] or error('Unknown units')
local outnum = invalue.number * convert.factor
local precision = invalue:getPrecision()
if outnum > 0 then
local adjust = math.log10(1/convert.factor) + math.log10(2)
precisionlocal p1 = math.max(math.floor(precision + adjust),
local p2 = 1 - math.floor(math.log10(outnum)))
if convert.p2max then
p2 = math.min(p2, convert.p2max)
end
precision = math.max(p1, p2)
end
self:setNumberRounded(outnum, precision)
Line 253 ⟶ 265:
end
for i = 1,13 do
local factorunits
if M_values[i].string == '' then
if I_values[i]:isValid() then
if v_class == 1 then
factorunits = 2.54'in2cm'
else
factorunits = 25.4'in2mm'
end
M_values[i]:setConvert( I_values[i], factorunits )
M_values[i].variant = v_class
end
Line 267 ⟶ 279:
if M_values[i]:isValid() then
if M_values[i].variant == 1 then
factorunits = 1/2.54'cm2in'
else
factorunits = 1/25.4'mm2in'
end
I_values[i]:setConvert( M_values[i], factorunits )
end
end