编辑 模块:NumberSpell 0 根据下列点原因,你没有权限进行操作编辑本页: 您刚才请求的操作只有以下用户组中的用户才能使用: 用户, FANDOM员工, FANDOM助手, Wiki主管, 内容团队人员 此页面已被保护,因为这个页面被以下已标注“联锁保护”的一个被保护页面包含: 社区中心 Please log in to edit this wiki.Joining 社区中心 is free, and it only takes a minute.We hope that you sign in, and become a member of the community!Click here to log in or create an account 更多 + 您可以查看并复制此页面的源代码: -- This module converts a number into its written English form. -- For example, "2" becomes "two", and "79" becomes "seventy-nine". local getArgs = require('Module:Arguments').getArgs local p = {} local max = 100 -- The maximum number that can be parsed. local ones = { [0] = '零', [1] = '一', [2] = '二', [3] = '三', [4] = '四', [5] = '五', [6] = '六', [7] = '七', [8] = '八', [9] = '九' } local specials = { [10] = '十', [20] = '二十', [30] = '三十', [40] = '四十', [50] = '五十', [60] = '六十', [70] = '七十', [80] = '八十', [90] = '九十', [100] = '一百' } local formatRules = { {num = 90, rule = '九十%s'}, {num = 80, rule = '八十%s'}, {num = 70, rule = '七十%s'}, {num = 60, rule = '六十%s'}, {num = 50, rule = '五十%s'}, {num = 40, rule = '四十%s'}, {num = 30, rule = '三十%s'}, {num = 20, rule = '二十%s'}, {num = 10, rule = '十%s'} } function p.main(frame) local args = getArgs(frame) local num = tonumber(args[1]) local success, result = pcall(p._main, num) if success then return result else return string.format('<strong class="error">Error: %s</strong>', result) -- "result" is the error message. end return p._main(num) end function p._main(num) if type(num) ~= 'number' or math.floor(num) ~= num or num < 0 or num > max then error('input must be an integer between 0 and ' .. tostring(max), 2) end -- Check for numbers from 0 to 9. local onesVal = ones[num] if onesVal then return onesVal end -- Check for special numbers. local specialVal = specials[num] if specialVal then return specialVal end -- Construct the number from its format rule. onesVal = ones[num % 10] if not onesVal then error('Unexpected error parsing input ' .. tostring(num)) end for i, t in ipairs(formatRules) do if num >= t.num then return string.format(t.rule, onesVal) end end error('No format rule found for input ' .. tostring(num)) end return p 返回到模块:NumberSpell。 编辑摘要 预览 显示差异