-- Local functions


local function FormatThousands(n) -- Credit to http://richard.warburton.it
	local left, num, right = string.match(n, '^([^%d]*%d)(%d*)(.-)$')
	return left .. (num:reverse():gsub('(%d%d%d)','%1,'):reverse()) .. right
end

local function ConvertToShortNum(number)
	local exponent = math.floor(math.log10(number))
	
	-- Check if the number is too short	
	if (exponent <= 2) then
		return tostring(number)
	end
	-- Create a table for the symbols
	local symbols = {
		[1] = { "3", "k" }, [2] = { "6", "M" }, [3] = { "9", "G" },
		[4] = { "12", "T" }, [5] = { "15", "P" }, [6] = { "18", "E" },
		[7] = { "21", "Z" }, [8] = { "24", "Y" }	
	}
	
	local suffix = ""
	local currentExponent = 1
			
	-- Loop through the symbols
	for index = 1, #symbols do
		local info = symbols[index] 
		
		-- Check if the index is not the last entry in the table
		if (index ~= #symbols) then			
			-- Check if the symbol's exponent is less than the number's
			if (exponent >= tonumber(info[1])) then
				-- Change the last exponent and suffix to the current symbol's
				currentExponent = tonumber(info[1])
				suffix = info[2]
				
				-- Continue so that the loop does not break
				continue
			end
			
			-- Break as the symbol's exponent is greater than the numbers
			break
		end
	end
	
	-- Get the divisor and the final string
	local divisor = math.pow(10, currentExponent)	
	local str =	("%.2f%s"):format(number / divisor, suffix) 	
	
	-- Return the string						
	return str
end
