Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:Ordinal

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
WarningThis Lua module is used onapproximately 259,000 pages.
To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on thetalk page before implementing them.

This module is meant to implement the{{Ordinal}} template. Please see the template page for usage instructions.

The abovedocumentation istranscluded fromModule:Ordinal/doc.(edit |history)
Editors can experiment in this module's sandbox(create |mirror) and testcases(create) pages.
Subpages of this module.

--[[This template will add the appropriate ordinal suffix to a given integer.Please do not modify this code without applying the changes first atModule:Ordinal/sandbox and testing.]]localp={}localyesno=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 parametersParameters    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.]]functionp.ordinal(frame)localargs=frame.argsifargs[1]==nilthenargs=frame:getParent().argsendifargs[1]==nilthenargs[1]="{{{1}}}"endreturnp._ordinal(args[1],(args[2]=='d'),yesno(args.sup))endfunctionp._ordinal(n,d,sup)localx=tonumber(mw.ustring.match(n,"(%d*)%W*$"))localsuffix="th"-- If tonumber(n) worked:ifxthenlocalmod10=math.abs(x)%10localmod100=math.abs(x)%100ifmod10==1andmod100~=11thensuffix="st"elseifmod10==2andmod100~=12thenifdthensuffix="d"elsesuffix="nd"endelseifmod10==3andmod100~=13thenifdthensuffix="d"elsesuffix="rd"endendendifsupthensuffix="<sup>"..suffix.."</sup>"endreturnn..suffixendreturnp
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Ordinal&oldid=888228748"
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp