FANDOM


-- Rounds a number to the nearest integer.
function round(fVal)
	return floor(fVal + 0.5)
end
 
-- Converts a decimal value into a fraction.
function decimal_to_fraction(fNumber)
	local fullNumber = floor(fNumber)
	local iNumerator = fNumber - fullNumber
	local iDenominator = 1
	while (iNumerator ~= floor(iNumerator)) do
		iNumerator = iNumerator * 10
		iDenominator = iDenominator * 10
	end
	iNumerator = floor(iNumerator)
	for i = 2, floor(sqrt(iNumerator)) do
		while ((mod(iNumerator, i) == 0) and (mod(iDenominator, i) == 0)) do
			iNumerator = iNumerator / i
			iDenominator = iDenominator / i
		end
	end
	iNumerator = iNumerator + fullNumber * iDenominator
--	print(fNumber .. " = " .. iNumerator .. "/" .. iDenominator)
	return iNumerator, iDenominator
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.