Module:ConvertCapacity: Difference between revisions
From Australian Enthusiasts Wiki
Spin off from Module:Validate platter capacity |
No edit summary |
||
| Line 13: | Line 13: | ||
return number * (1000 ^ stepsRemoved) | 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 | end | ||
Revision as of 21:54, 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