Module:Ordinal Number

local p = {}

local yesno = require('Module:Yesno') -- boolean value interpretation

function p._(frame) local args = frame.args if args[1] == nil then args = frame:getParent.args end if args[1] == nil then args[1] = "" end end

function p.integer(frame) p._ return p._integer(args[1], yesno(args.sup)) end

function p._integerl(n, d, sup) local x = tonumber(mw.ustring.match(n, "(%d*)%W*$")) local suffix = "th" -- If tonumber(n) worked: if x then local mod10 = math.abs(x) % 10 local mod100 = math.abs(x) % 100 if mod10 == 1 and mod100 ~= 11 then suffix = "st" elseif mod10 == 2 and mod100 ~= 12 then suffix = "nd" elseif mod10 == 3 and mod100 ~= 13 then suffix = "rd" end end if sup then suffix = "" .. suffix .. ""	end return n .. suffix end

return p