Module:ConvertCapacity: Difference between revisions
From Australian Enthusiasts Wiki
No edit summary |
Forgot the return p |
||
| Line 19: | Line 19: | ||
return p.convertCapacity(tonumber(frame.args[1]), frame.args[2], frame.args[3]) | return p.convertCapacity(tonumber(frame.args[1]), frame.args[2], frame.args[3]) | ||
end | end | ||
return p | |||
Revision as of 22:01, 11 September 2022
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