Module:ConvertCapacity
From Computing Classics Wiki
Documentation for this module may be created at Module:ConvertCapacity/doc
local p = {}
-- Convert a capacity from one target to another.
function p.convertCapacity(number, from, to)
-- Return immediately if the unit from and to are the same.
if (from == to) then
return number
end
unitArray = {"mb", "mib", "gb", "gib", "tb", "tib", "eb", "eib"}
stepsRemoved = (p.indexOf(unitArray, from) - p.indexOf(unitArray, to)) / 2
return number * (1000 ^ stepsRemoved)
end
-- Main entry point for this module.
function p.invokeMain(frame)
return p.convertCapacity(tonumber(frame.args[1]), frame.args[2], frame.args[3])
end
return p