Sari la conținut

Modul:Formatnum

De la Wikipedia, enciclopedia liberă
local p = {}


-- this function receives a number, tries to guess the layout and returns the 
-- same number with the thousand separator stripped and the decimal separator
-- converted to English format
p.stripSeparators = function(input)
	local comma = ','
	local dot = '\.'
	local _, commaCount = string.gsub(input, comma, comma)
	local _, dotCount = string.gsub(input, dot, dot)
	mw.logObject(commaCount, "Comma count")
	mw.logObject(dotCount, "Dot count")
	if dotCount == 0 then
		if commaCount == 0 then --plain old integer
			return tonumber(input)
		elseif commaCount == 1 then -- floating point, Romanian format
			return tonumber(string.gsub(input, comma, dot))
		else -- integer with thousand separator
			return tonumber(input)
		end
	end
end

return p