Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Spellnum per MOS
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local words = {"thousand", "million", "billion", "trillion"} -- We don't need to go higher than this, no-one knows what an octillion is. -- For use by other scripts. Takes arguments: -- - 1: string or number, value to convert -- - forcenum: string for Template:Yesno, forces a result in digits for all n β₯ 10. -- - formating options for spellnum: zero, adj, ord, us function p.spellnum(args) local frame = mw.getCurrentFrame() local numeral = tonumber(args[1]) local pass_zero = "zero" if args['zero'] ~= nil and args['zero'] ~= '' then pass_zero = args['zero'] end -- Always return numerals for negative numbers, non-integers, and if (forcenum and numeral >= 10). if numeral < 0 or math.fmod(numeral, 1) ~= 0 or (numeral >= 10 and frame:expandTemplate{ title = 'yesno', args = {args['forcenum']} } == 'yes') then return mw.language.getContentLanguage():formatNum(numeral) end -- Convert numeral to words local spelled = frame:expandTemplate{ title = 'spellnum', args = { numeral, zero = pass_zero, adj = args['adj'], ord = args['ord'], us = args['us']}} -- Return numerals if more than two words would be needed, else return words if mw.ustring.find(spelled,'%a+[ %-]%a+[ %-]%a+') then -- Handle numbers larger than one million if numeral >= 1000000 and numeral <= 1000000000000000 then local size = math.min(4, math.floor(math.log10(numeral) / 3)) numeral = numeral / 1000^size return ({"%.1f ", "%d ", "%d "})[1 + math.floor(math.log10(numeral))]:format(numeral) .. words[size] end return mw.language.getContentLanguage():formatNum(numeral) else return spelled end end function p.main(frame) return p.spellnum(frame.args) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Tl
(
edit
)
Module:Spellnum per MOS/doc
(
edit
)