2,875
edits
(Add rounding of item quantity) |
(Add dynamic decimal place rounding) |
||
Line 26: | Line 26: | ||
--return frame:preprocess(str) | --return frame:preprocess(str) | ||
end | end | ||
-- Determines how many decimal places a number should get. | |||
-- This is to get some sensible rounding for small and large numbers. | |||
local function getDecimalPlaces(number) | |||
-- Decimal places for items smaller than 0 | |||
if number >= 1000 then return 0 | |||
elseif number >= 100 then return 1 | |||
elseif number >= 0.01 then return 2 | |||
elseif number >= 0.001 then return 3 | |||
elseif number >= 0.0001 then return 4 | |||
elseif number >= 0.00001 then return 5 | |||
else return 6 | |||
end | |||
end | |||
--- Formats a given string to TitleCase. | --- Formats a given string to TitleCase. | ||
Line 193: | Line 207: | ||
qtyCell:node(getErrorDiv("Unable to parse quantity for item: " .. i.name)) | qtyCell:node(getErrorDiv("Unable to parse quantity for item: " .. i.name)) | ||
else | else | ||
local qty = num.round2(i.amount, | local roundDecimals = getDecimalPlaces(i.amount) | ||
local qty = num.round2(i.amount, roundDecimals) | |||
qtyCell:wikitext(num.formatnum(qty)) | qtyCell:wikitext(num.formatnum(qty)) | ||
end | end |
edits