Module:Convert: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Theodore O'Connor was a {{hands|14.1+3/4}} pony means 14 hands + 1.75 inches = 57.75 inches (although module rounds that to 57.8 by default)) |
(builtin hand units default to show name not symbol since "h" is "hour" and is uncommon for "hand") |
||
Line 694: | Line 694: | ||
-- [[mile]]s per [[United States customary units|U.S.]] [[quart]] |
-- [[mile]]s per [[United States customary units|U.S.]] [[quart]] |
||
-- [[long ton]]s per [[short ton]] |
-- [[long ton]]s per [[short ton]] |
||
-- Assume that links cannot be nested (never like "[[abc[[def]]ghi]]". |
-- Assume that links cannot be nested (never like "[[abc[[def]]ghi]]"). |
||
-- This uses a simple and efficient procedure that works for most cases. |
-- This uses a simple and efficient procedure that works for most cases. |
||
-- Some units (if used) would require more, and can later think about |
-- Some units (if used) would require more, and can later think about |
||
Line 1,833: | Line 1,833: | ||
-- Input info.clean uses en digits (it has been translated, if necessary). |
-- Input info.clean uses en digits (it has been translated, if necessary). |
||
-- Output show uses en or non-en digits as appropriate, or can be spelled. |
-- Output show uses en or non-en digits as appropriate, or can be spelled. |
||
local invalue, inclean |
local invalue, inclean |
||
if info then |
if info then |
||
invalue, inclean = info.value, info.clean |
invalue, inclean = info.value, info.clean |
||
Line 1,848: | Line 1,848: | ||
-- precision if the output uses scientific notation (very large, or very |
-- precision if the output uses scientific notation (very large, or very |
||
-- small). Not worth more complexity as these cases should be very rare. |
-- small). Not worth more complexity as these cases should be very rare. |
||
if parms.abbr_org == nil then |
|||
out_current.usename = true -- default is to show name not symbol |
|||
⚫ | |||
local dummy_unit_table = { scale = out_current.scale } |
local dummy_unit_table = { scale = out_current.scale } |
||
local success, outinfo = cvtround(parms, info, in_current, dummy_unit_table) |
local success, outinfo = cvtround(parms, info, in_current, dummy_unit_table) |
||
Line 1,877: | Line 1,880: | ||
inches = inches:sub(1, 1) .. inches:sub(3) |
inches = inches:sub(1, 1) .. inches:sub(3) |
||
end |
end |
||
⚫ | |||
return true, { |
|||
return true, outinfo |
|||
singular = outinfo.singular, |
|||
⚫ | |||
⚫ | |||
end |
end |
||
local outvalue, extra = convert(invalue, inclean, in_current, out_current) |
local outvalue, extra = convert(invalue, inclean, in_current, out_current) |
||
Line 1,898: | Line 1,898: | ||
outvalue = -outvalue |
outvalue = -outvalue |
||
end |
end |
||
local success, use_default_precision |
local success, use_default_precision, show, exponent |
||
local precision = parms.precision |
local precision = parms.precision |
||
if not precision then |
if not precision then |
||
Line 1,935: | Line 1,935: | ||
end |
end |
||
end |
end |
||
end |
|||
⚫ | |||
⚫ | |||
singular = true |
|||
end |
end |
||
local t = format_number(parms, show, exponent, isnegative) |
local t = format_number(parms, show, exponent, isnegative) |
||
⚫ | |||
t.singular = singular |
|||
⚫ | |||
t.raw_absvalue = outvalue -- absolute value before rounding |
t.raw_absvalue = outvalue -- absolute value before rounding |
||
t.use_default_precision = use_default_precision |
t.use_default_precision = use_default_precision |