VOOZH about

URL: https://minecraft.wiki/w/Module:NumberSpell

⇱ Module:NumberSpell – Minecraft Wiki


Module:NumberSpell

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[create] [purge]
This module has no documentation. If you know how to use this module, please create it.
-- This module converts a number into its written English form.
-- For example, "2" becomes "two", and "79" becomes "seventy-nine".
localgetArgs=require('Module:Arguments').getArgs
localp={}
localmax=100-- The maximum number that can be parsed.
localones={
[0]='zero',
[1]='one',
[2]='two',
[3]='three',
[4]='four',
[5]='five',
[6]='six',
[7]='seven',
[8]='eight',
[9]='nine'
}
localspecials={
[10]='ten',
[11]='eleven',
[12]='twelve',
[13]='thirteen',
[15]='fifteen',
[18]='eighteen',
[20]='twenty',
[30]='thirty',
[40]='forty',
[50]='fifty',
[60]='sixty',
[70]='seventy',
[80]='eighty',
[90]='ninety',
[100]='one hundred'
}
localformatRules={
{num=90,rule='ninety-%s'},
{num=80,rule='eighty-%s'},
{num=70,rule='seventy-%s'},
{num=60,rule='sixty-%s'},
{num=50,rule='fifty-%s'},
{num=40,rule='forty-%s'},
{num=30,rule='thirty-%s'},
{num=20,rule='twenty-%s'},
{num=10,rule='%steen'}
}
functionp.main(frame)
localargs=getArgs(frame)
localnum=tonumber(args[1])
localsuccess,result=pcall(p._main,num)
ifsuccessthen
returnresult
else
returnstring.format('<strong class="error">Error: %s</strong>',result)-- "result" is the error message.
end
returnp._main(num)
end
functionp._main(num)
iftype(num)~='number'ormath.floor(num)~=numornum<0ornum>maxthen
error('input must be an integer between 0 and '..tostring(max),2)
end
-- Check for numbers from 0 to 9.
localonesVal=ones[num]
ifonesValthen
returnonesVal
end
-- Check for special numbers.
localspecialVal=specials[num]
ifspecialValthen
returnspecialVal
end
-- Construct the number from its format rule.
onesVal=ones[num%10]
ifnotonesValthen
error('Unexpected error parsing input '..tostring(num))
end
fori,tinipairs(formatRules)do
ifnum>=t.numthen
returnstring.format(t.rule,onesVal)
end
end
error('No format rule found for input '..tostring(num))
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:NumberSpell?oldid=1328282"

Navigation menu