<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AGapnum</id>
	<title>Module:Gapnum - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AGapnum"/>
	<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Gapnum&amp;action=history"/>
	<updated>2026-04-04T17:24:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://the-democratika.com/wiki/index.php?title=Module:Gapnum&amp;diff=7129&amp;oldid=prev</id>
		<title>&gt;MusikAnimal: Changed protection level for &quot;Module:Gapnum&quot;: High-risk Lua module: 7,000+ transclusions ([Edit=Require extended confirmed access] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Gapnum&amp;diff=7129&amp;oldid=prev"/>
		<updated>2017-10-10T17:39:00Z</updated>

		<summary type="html">&lt;p&gt;Changed protection level for &amp;quot;&lt;a href=&quot;/wiki/index.php/Module:Gapnum&quot; title=&quot;Module:Gapnum&quot;&gt;Module:Gapnum&lt;/a&gt;&amp;quot;: &lt;a href=&quot;/wiki/index.php?title=WP:High-risk_templates&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;WP:High-risk templates (page does not exist)&quot;&gt;High-risk Lua module&lt;/a&gt;: 7,000+ transclusions ([Edit=Require extended confirmed access] (indefinite))&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
local getArgs&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	if not getArgs then&lt;br /&gt;
		getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local args = getArgs(frame, {wrappers = &amp;#039;Template:Gapnum&amp;#039;})&lt;br /&gt;
	local n = args[1]&lt;br /&gt;
&lt;br /&gt;
	if not n then&lt;br /&gt;
		error(&amp;#039;Parameter 1 is required&amp;#039;)&lt;br /&gt;
	elseif not tonumber(n) and not tonumber(n, 36) then -- Validates any number with base ≤ 36&lt;br /&gt;
		error(&amp;#039;Unable to convert &amp;quot;&amp;#039; .. args[1] .. &amp;#039;&amp;quot; to a number&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local gap = args.gap&lt;br /&gt;
	local precision = tonumber(args.prec)&lt;br /&gt;
&lt;br /&gt;
	return p.gaps(n,{gap=gap,prec=precision})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Not named p._main so that it has a better function name when required by Module:Val&lt;br /&gt;
function p.gaps(n,tbl)&lt;br /&gt;
	local nstr = tostring(n)&lt;br /&gt;
	if not tbl then&lt;br /&gt;
		tbl = {}&lt;br /&gt;
	end&lt;br /&gt;
	local gap = tbl.gap or &amp;#039;.25em&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	local int_part, frac_part = p.groups(n,tbl.prec)&lt;br /&gt;
&lt;br /&gt;
	local ret = mw.html.create(&amp;#039;span&amp;#039;)&lt;br /&gt;
							:css(&amp;#039;white-space&amp;#039;,&amp;#039;nowrap&amp;#039;)&lt;br /&gt;
							-- No gap necessary on first group&lt;br /&gt;
							:wikitext(table.remove(int_part,1))&lt;br /&gt;
&lt;br /&gt;
	-- Build int part&lt;br /&gt;
	for _, v in ipairs(int_part) do&lt;br /&gt;
		ret:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;margin-left&amp;#039;,gap)&lt;br /&gt;
				:wikitext(v)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if frac_part then&lt;br /&gt;
		-- The first group after the decimal shouldn&amp;#039;t have a gap&lt;br /&gt;
		ret:wikitext(&amp;#039;.&amp;#039; .. table.remove(frac_part,1))&lt;br /&gt;
		-- Build frac part&lt;br /&gt;
		for _, v in ipairs(frac_part) do&lt;br /&gt;
			ret:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;margin-left&amp;#039;,gap)&lt;br /&gt;
					:wikitext(v)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Creates tables where each element is a different group of the number&lt;br /&gt;
function p.groups(num,precision)&lt;br /&gt;
	local nstr = tostring(num)&lt;br /&gt;
	if not precision then&lt;br /&gt;
		precision = -1&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local decimalloc = nstr:find(&amp;#039;.&amp;#039;, 1, true)&lt;br /&gt;
	local int_part, frac_part&lt;br /&gt;
	if decimalloc == nil then&lt;br /&gt;
		int_part = nstr&lt;br /&gt;
	else&lt;br /&gt;
		int_part = nstr:sub(1, decimalloc-1)&lt;br /&gt;
		frac_part = nstr:sub(decimalloc + 1)&lt;br /&gt;
	end&lt;br /&gt;
	-- only define ret_i as an empty table, let ret_d stay nil&lt;br /&gt;
	local ret_i,ret_d = {}&lt;br /&gt;
	-- Loop to handle most of the groupings; from right to left, so that if a group has less than 3 members, it will be the first group&lt;br /&gt;
	while int_part:len() &amp;gt; 3 do&lt;br /&gt;
		-- Insert in first spot, since we&amp;#039;re moving backwards&lt;br /&gt;
		table.insert(ret_i,1,int_part:sub(-3))&lt;br /&gt;
		int_part = int_part:sub(1,-4)&lt;br /&gt;
	end&lt;br /&gt;
	-- handle any left over numbers&lt;br /&gt;
	if int_part:len() &amp;gt; 0 then&lt;br /&gt;
		table.insert(ret_i,1,int_part)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if precision ~= 0 and frac_part then&lt;br /&gt;
		ret_d = {}&lt;br /&gt;
		if precision == -1 then&lt;br /&gt;
			precision = frac_part:len()&lt;br /&gt;
		end&lt;br /&gt;
		-- Reduce the length of the string if required precision is less than actual precision&lt;br /&gt;
		-- OR&lt;br /&gt;
		-- Increase it (by adding 0s) if the required precision is more than actual&lt;br /&gt;
		local offset = precision - frac_part:len()&lt;br /&gt;
		if offset &amp;lt; 0 then&lt;br /&gt;
			frac_part = frac_part:sub(1,precision)&lt;br /&gt;
		elseif offset &amp;gt; 0 then&lt;br /&gt;
			frac_part = frac_part .. string.rep(&amp;#039;0&amp;#039;, offset)&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- Allow groups of 3 or 2 (3 first)&lt;br /&gt;
		for v in string.gmatch(frac_part,&amp;#039;%d%d%d?&amp;#039;) do&lt;br /&gt;
			table.insert(ret_d,v)&lt;br /&gt;
		end&lt;br /&gt;
		-- Preference for groups of 4 instead of groups of 1 at the end&lt;br /&gt;
		if #frac_part % 3 == 1 then&lt;br /&gt;
			if frac_part:len() == 1 then&lt;br /&gt;
				ret_d = {frac_part}&lt;br /&gt;
			else&lt;br /&gt;
				local last_g = ret_d[#ret_d] or &amp;#039;&amp;#039;&lt;br /&gt;
				last_g = last_g..frac_part:sub(-1)&lt;br /&gt;
				ret_d[#ret_d] = last_g&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return ret_i,ret_d&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>&gt;MusikAnimal</name></author>
	</entry>
</feed>