https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ASpellnum_per_MOS%2FsandboxModule:Spellnum per MOS/sandbox - Revision history2025-06-06T14:12:32ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.4https://en.wikipedia.org/w/index.php?title=Module:Spellnum_per_MOS/sandbox&diff=1027948712&oldid=prevGKFX: Create sandbox version of Module:Spellnum per MOS2021-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 = {"thousand", "million", "billion", "trillion"} -- We don'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 >= 10).<br />
if numeral < 0 or<br />
math.fmod(numeral, 1) ~= 0 or<br />
(numeral >= 10 and frame:expandTemplate{ title = 'yesno', args = {args['forcenum']} } == 'yes') then<br />
return mw.language.getContentLanguage():formatNum(numeral)<br />
end<br />
<br />
local spelled = frame:expandTemplate{ title = 'spellnum', args = {<br />
numeral, zero = args['zero'], adj = args['adj'], ord = args['ord'], us = args['us']}}<br />
<br />
if mw.ustring.find(spelled,'%a+[ %-]%a+[ %-]%a+') then<br />
if numeral >= 1000000 and numeral <= 1000000000000000 then<br />
local size = math.min(4, math.floor(math.log10(numeral) / 3))<br />
numeral = numeral / 1000^size<br />
return ({"%.2f ", "%.1f ", "%d "})[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