Module:Convert: Difference between revisions

fixes for default rounding with composite input units
(sortable=on, sp=us, customary_units moved to Module:Convert/text; don't link a unit twice; tweaks: will have to fix LTf, STf another time)
(fixes for default rounding with composite input units)
Line 1,161:
local prec, minprec, adjust
local utype = out_current.utype
local subunit_ignore_trailing_zero
local subunit_more_precision -- kludge for "in" used in input like "|2|ft|6|in"
local composite = in_current.composite
if composite then
subunit_ignore_trailing_zero = true -- input "|2|st|10|lb" has precision 0, not -1
if composite[2].exception == 'subunit_more_precision' then
subunit_more_precision = true -- do not use standard precision with input like "|2|ft|6|in"
end
end
-- Count digits after decimal mark, handling cases like '12.345e6'.
local exponent
Line 1,169 ⟶ 1,178:
end
if dot == '' then
prec = subunit_ignore_trailing_zero and 0 or -integer:match('0*$'):len()
else
prec = #fraction
Line 1,196 ⟶ 1,205:
return 0
end
if out_current.exception == 'moreprecisioninteger_more_precision' and floor(invalue) == invalue then
-- With certain output units that sometimes give poor results
-- with default rounding, use more precision when the input
Line 1,205 ⟶ 1,214:
-- interpreted as "from 45 to 55" or "from 49.5 to 50.5".
adjust = -log10(in_current.scale)
elseif subunit_more_precision then
-- Conversion like "{{convert|6|ft|1|in|cm}}" (where subunit is "in")
-- has a non-standard adjust value, to give more output precision.
adjust = log10(out_current.scale) + 2
else
adjust = log10(abs(invalue / outvalue))
Anonymous user