Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 21:23, 4 December 2013 by commons>Snævar (Created page with '-- This module is intended to replace the functionality of Template:Formatnum and related templates. -- This module is in beta. Use with caution. local p = {}...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Module documentation[ create · purge ]
This documentation is transcluded from Module:Formatnum/doc.
-- This module is intended to replace the functionality of Template:Formatnum and related templates.
-- This module is in beta. Use with caution.
local p = {}

function p.main(frame)
	local pframe = frame:getParent()
	local config = frame.args
	local args = pframe.args
	
	if tonumber(args.prec) ~= nil and tonumber(args.prec) > 0 and tonumber(args[1]) ~= nil then
		if string.find(tostring(args[1]), "%.") ~= nil then
			precnumber = string.sub(args[1], 1, (string.find(tostring(args[1]), "%.") + args.prec))
		else
			precnumber = "" .. args[1] .. "." .. string.rep("0", args.prec)
		end
		number = "" .. precnumber .. "1"
		precA = "true"
	else
		number = args[1]
	end
		
	if tonumber(number) ~= nil and mw.language.isSupportedLanguage(args[2] or "") == true then
		formatnum = mw.getLanguage( args[2] ):formatNum( tonumber(number) )
	elseif tonumber(number) ~= nil then
		formatnum = mw.getLanguage(frame:preprocess( "{{int:lang}}" )):formatNum(tonumber(number))
	else
		formatnum = ""
	end
	
	if precA == "true" then
		postprec = string.sub(formatnum, 1, (string.len(formatnum) - 1))
	else
		postprec = formatnum
	end
	
	-- Eqvaluent functions to Template:FormatnumSigns
	-- Table over what thousands seperator is used.
	thousand = {
		ckb="٫",
		fa="٫",
		glk="٫",
		ks="٫",
		mzn="٫",
		ur=",",
		ca=".",
		da=",",
		de=",",
		gl=",",
		mk=",",
		nds=",",
		nl=",",
		sl=",",
		cs=",",
		fr=",",
		hu=",",
		ro=",",
		pl=",",
		nb=",",
		nn=",",
		no=",",
		sv=",",
		bn=".",
		ml=".",
		hi=".",
		sa=".",
		ta=".",
		kn=".",
		te=".",
		mr=".",
		["or"]=".",
		pa=".",
		gu=".",
		bho=".",
		as="."
	}
	-- Table ends
	if args.sep ~= nil then
		local replace = mw.ustring.gsub( "", "%%", "%%%%" )
		local pattern = mw.ustring.gsub( (thousand[args[2] or frame:preprocess( "{{int:lang}}" )] or "."), "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
		return tostring(mw.ustring.gsub( postprec, pattern, replace ))
	else
		return postprec
	end
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.