Module:MoneyMakingGuide: Difference between revisions

m
Use autoround instead for rounding
(Add one extra decimal place to dynamic rounding)
m (Use autoround instead for 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.1 then return 2
    elseif number >= 0.01 then return 3
    elseif number >= 0.001  then return 4
    elseif number >= 0.0001 then return 5
    elseif number >= 0.00001 then return 6
    else return 7
    end
end


--- Formats a given string to TitleCase.
--- Formats a given string to TitleCase.
Line 208: Line 193:
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 roundDecimals = getDecimalPlaces(i.amount)
local qty = num.autoround(i.amount)
local qty = num.round2(i.amount, roundDecimals)
qtyCell:wikitext(num.formatnum(qty))
qtyCell:wikitext(num.formatnum(qty))
end
end
2,875

edits