Difference between revisions of "Template:ordinal"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
m (adding to category)
m (added some code to make defined behavior for non-integer numbers. might try to make it use)
Line 1: Line 1:
βˆ’
<includeonly>{{formatnum: {{#expr: {{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}} }} |{{#if:{{#pos:{{{2|}}}|R}}|R}} }}{{#if:{{#pos:{{{2|}}}|S}}||<sup>}}{{#ifexpr:10<=abs({{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}}) mod 100 and abs({{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}}) mod 100<=20|th|{{#switch:{{#expr:abs({{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}}) mod 10}}|1=st|2=nd|3=rd|th}}}}{{#if:{{#pos:{{{2|}}}|S}}||</sup>}}</includeonly><noinclude>
+
<includeonly>{{formatnum: {{#expr: {{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}} }} |{{#if:{{#pos:{{{2|}}}|R}}|R}} }}{{#if:{{#pos:{{{2|}}}|S}}||<sup>}}{{#ifexpr:10<=floor(abs({{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}})) mod 100 and floor(abs({{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}})) mod 100<=20|th|{{#switch:{{#expr:floor(abs({{formatnum:{{#if:{{{1|}}}|{{{1|}}}|0}}|R}})) mod 10}}|1=st|2=nd|3=rd|th}}}}{{#if:{{#pos:{{{2|}}}|S}}||</sup>}}</includeonly><noinclude>
  
 
This properly formats the given number as an abbreviated ordinal number in English.
 
This properly formats the given number as an abbreviated ordinal number in English.

Revision as of 03:36, 1 February 2025


This properly formats the given number as an abbreviated ordinal number in English.

Usage

{{ordinal|number[|flags(optional)]}}

  • number is the number to be formatted
    - Negative numbers get formatted as positive numbers with an negative sign added to the front of the number.
    - 0 gets formatted as "Zeroth".
  • flags indicates flags for the format of the output
    - If "R" is in flags, the output is formatted without commas.
    - If "S" is in flags, the output is formatted with the ordinal indicators not in superscripts.
    - Flags can be combined in any order.
    - If flags is omitted, the output is formatted as if no flags were given.

Examples

  • {{ordinal|1}}
produces
1st
  • {{ordinal|0002}}
produces
2nd
  • {{ordinal|0}}
produces
0th
  • {{ordinal|-00003}}
produces
-3rd
  • {{ordinal|123456789}}
produces
123,456,789th
  • {{ordinal|983,675,911}}
produces
983,675,911th
  • {{ordinal|123456|S}}
produces
123,456th
  • {{ordinal|00,314,159|R}}
produces
314159th
  • {{ordinal|-271828|RS}}
produces
-271828th
  • {{ordinal}}
produces
0th
First 29 ordinal numbers in English
Number Ordinal Number Ordinal Number Ordinal
0 0th 10 10th 20 20th
1 1st 11 11th 21 21st
2 2nd 12 12th 22 22nd
3 3rd 13 13th 23 23rd
4 4th 14 14th 24 24th
5 5th 15 15th 25 25th
6 6th 16 16th 26 26th
7 7th 17 17th 27 27th
8 8th 18 18th 28 28th
9 9th 19 19th 29 29th