Module:Rates
From Ephinea PSO Wiki
Documentation for this module may be created at Module:Rates/doc
local wholeFractions = { [0.9] = "9/10", [0.88] = "22/25", [0.875] = "7/8", [0.85] = "17/20", [0.8] = "4/5", [0.6] = "3/5", [0.5625] = "9/16", [0.55] = "9/20" } local function calcRate(dar, rdr) return dar*rdr end local function trimRate(rate, fmt, digits) local out = "" if digits == nil then digits = 0 end if fmt == "f" then if rate < 10 then digits = math.max(digits, 2) elseif rate < 100 then digits = math.max(digits, 1) else digits = math.max(digits, 0) end out = out .. string.format("%f", string.format(" %." .. digits .. "f", rate)):gsub("%.?0+$", "") return out elseif fmt == "p" then rate = string.format("%f", string.format(" %.5f", rate)):gsub("%.?0+$", "") out = out .. rate return out end end local function displayRate(rate, fmt, digits) local out = "" if fmt == "f" then if wholeFractions[rate] == nil then out = out .. string.format("1/%s", trimRate(1/rate, "f", digits)) else out = out .. wholeFractions[rate] end end if fmt == "p" then out = out .. string.format("%s%%", trimRate(rate*100, "p")) end if fmt == "n" then out = out .. displayRate(rate, "f", 2) .. " (" .. displayRate(rate, "p") .. ")" end return out end