Editing
Module:Ordinal
Jump to navigation
Jump to search
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!
--[[ This template will add the appropriate ordinal suffix to a given integer. Please do not modify this code without applying the changes first at Module:Ordinal/sandbox and testing. ]] local p = {} local yesno = require('Module:Yesno') -- boolean value interpretation --[[ This function converts an integer value into a numeral followed by ordinal indicator. The output string might contain HTML tags. Usage: {{#invoke:Ordinal|ordinal|1=|2=|sup=}} {{#invoke:Ordinal|ordinal}} - uses the caller's parameters Parameters 1: Any number or string. 2: Set to "d" if the module should display "d" instead of "nd" and "rd". sup: Set to yes/no to toggle superscript ordinal suffix. ]] function p.ordinal(frame) local args = frame.args if args[1] == nil then args = frame:getParent().args end if args[1] == nil then args[1] = "{{{1}}}" end return p._ordinal(args[1], (args[2] == 'd'), yesno(args.sup)) end function p._ordinal(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 if d then suffix = "d" else suffix = "nd" end elseif mod10 == 3 and mod100 ~= 13 then if d then suffix = "d" else suffix = "rd" end end end if sup then suffix = "<sup>" .. suffix .. "</sup>" end return n .. suffix end return p
Summary:
Please note that all contributions to Shut Down 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
NUSA Wiki Archive:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Ordinal/doc
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Tools
What links here
Related changes
Special pages
Page information