Module:Convert: Difference between revisions

(update from sandbox per Template talk:Convert#Module version 6)
(update from sandbox per Template talk:Convert#Module version 7)
Line 1,333:
-- altvalue = a valid number, usually same as value but different
-- if fraction used (for hands unit)
-- singular = true if value is 1 or -1 (to use singular form of units)
-- = false if value is -1 (like old template)
-- clean = cleaned text with any separators and sign removed
-- (en digits and '.' decimal mark)
Line 1,401 ⟶ 1,400:
end
if show == nil then
singular = (value == 1 and not isnegative)
local precision = parms.input_precision
if precision and 0 <= precision and precision <= 8 then
Line 1,781 ⟶ 1,780:
parms.opt_values = true
end
local align = format('alignstyle="text-align: %s;"', parms.opt_table and 'right' or 'center')
parms.table_joins = { align .. '|', '\n|' .. align .. '|' }
end
Line 2,274 ⟶ 2,273:
-- show = rounded, formatted string with the result of converting value in info,
-- using the rounding specified in parms.
-- singular = true if result is(after positive,rounding and (afterignoring roundingany negative sign)
-- is "1", or like "1.00", or is a fraction with value < 1;
-- (and more fields shown below, and a calculated 'absvalue' field).
-- or return true, nil if no value specified;
Line 2,362 ⟶ 2,361:
end
local t = format_number(parms, show, exponent, isnegative)
if inouttype(show) == 'instring' then
-- Set singular using match because on some systems 0.99999999999999999 is 1.0.
t.singular = (type(show) == 'string' and (show == '1' or show:match('^1%.0*$') ~= nil) and not isnegative)
if want_linkexponent then
t.fraction_table = (type(show) == 'table') and show or nil
t.singular = (exponent == 1 and show:match('^10*$'))
else
t.singular = (type(show) == 'string' and (show == '1' or show:match('^1%.0*$') ~= nil) and not isnegative)
end
else
t.fraction_table = show
t.singular = (outvalue <= 1) -- cannot have 'fraction == 1', but if it were possible it would be singular
end
t.raw_absvalue = outvalue -- absolute value before rounding
return true, setmetatable(t, {
Line 2,733 ⟶ 2,740:
local usename = unit_table.usename
local singular = info.singular
if usename then
-- Old template does something like this.
if want_link then
-- A linked unit uses the standard singular.
else
-- Set non-standard singular.
local flipped = parms.opt_flip
if inout == 'in' then
if not adjectival and (abbr_org == 'out' or flipped) then
local value = info.value
singular = (0 < value and value < 1.0001)
end
else
if (abbr_org == 'on') or
(not flipped and (abbr_org == nil or abbr_org == 'out')) or
(flipped and abbr_org == 'in') then
singular = (info.absvalue < 1.0001 and
not info.is_scientific)
end
end
end
end
local want_name
if usename then
Line 2,901 ⟶ 2,886:
local join1 = parms.joins[1]
if join1 == ' (' or join1 == ' [' then
parms.joins = { join1' [' .. first_unit[first_unit.sp_us and 'sym_us' or 'symbol'] .. ', ]' .. join1 , parms.joins[2] }
end
end
Anonymous user