Module:ConvertCapacity

From Computing Classics Wiki
Revision as of 12:01, 11 September 2022 by TheDragonFire123 (talk | contribs) (Forgot the return p)

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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.