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