https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ASpellnum_per_MOS%2Fsandbox Module:Spellnum per MOS/sandbox - Revision history 2025-06-06T14:12:32Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.4 https://en.wikipedia.org/w/index.php?title=Module:Spellnum_per_MOS/sandbox&diff=1027948712&oldid=prev GKFX: Create sandbox version of Module:Spellnum per MOS 2021-06-10T23:20:07Z <p>Create sandbox version of <a href="/wiki/Module:Spellnum_per_MOS" title="Module:Spellnum per MOS">Module:Spellnum per MOS</a></p> <p><b>New page</b></p><div>local p = {}<br /> local words = {&quot;thousand&quot;, &quot;million&quot;, &quot;billion&quot;, &quot;trillion&quot;} -- We don&#039;t need to go higher than this, no-one knows what an octillion is.<br /> <br /> -- For use by other scripts. Takes arguments:<br /> -- - 1: string or number, value to convert<br /> -- - forcenum: string for Template:Yesno, forces a result in digits for all n ≥ 10.<br /> -- - formating options for spellnum: zero, adj, ord, us<br /> -- WARNING: zero defaults to blank which is probably not what you want.<br /> function p.spellnum(args)<br /> local frame = mw.getCurrentFrame()<br /> local numeral = tonumber(args[1])<br /> <br /> -- Always return as digits for negative numbers, non-integers, and if (forcenum and numeral &gt;= 10).<br /> if numeral &lt; 0 or<br /> math.fmod(numeral, 1) ~= 0 or<br /> (numeral &gt;= 10 and frame:expandTemplate{ title = &#039;yesno&#039;, args = {args[&#039;forcenum&#039;]} } == &#039;yes&#039;) then<br /> return mw.language.getContentLanguage():formatNum(numeral)<br /> end<br /> <br /> local spelled = frame:expandTemplate{ title = &#039;spellnum&#039;, args = {<br /> numeral, zero = args[&#039;zero&#039;], adj = args[&#039;adj&#039;], ord = args[&#039;ord&#039;], us = args[&#039;us&#039;]}}<br /> <br /> if mw.ustring.find(spelled,&#039;%a+[ %-]%a+[ %-]%a+&#039;) then<br /> if numeral &gt;= 1000000 and numeral &lt;= 1000000000000000 then<br /> local size = math.min(4, math.floor(math.log10(numeral) / 3))<br /> numeral = numeral / 1000^size<br /> return ({&quot;%.2f &quot;, &quot;%.1f &quot;, &quot;%d &quot;})[1 + math.floor(math.log10(numeral))]:format(numeral) .. words[size]<br /> end<br /> return mw.language.getContentLanguage():formatNum(numeral)<br /> else <br /> return spelled<br /> end<br /> end<br /> <br /> function p.main(frame)<br /> return p.spellnum(frame.args)<br /> end<br /> <br /> return p</div> GKFX