# GMLAdding Ordinal Indicators to numbers (1st, 2nd, 3rd, 4th etc)

#### MrDave

##### Member
GM Version: ALL
Target Platform: ALL

Ordinal Indicators are the letters in 1st, 2nd, 3rd, 4th etc.

I’ve written a quick script for people wanting to add the correct letters to the end of an integer.

This isn’t going to be helpful for most people, but it can be tricky for people that haven’t done it before.

Code:
``````/// ordinalindicator(int) returns the int as a str with st, nd, rd or th at the end

if( argument0 <= 0 ) return argument0; //technically ordinals don't exist for <= 0

if ((argument0 mod 100) >= 11 and (argument0 mod 100) <= 13) {
return string(argument0) + "th";
}

switch(argument0 mod 10)
{
case 1:
return string(argument0) + "st";
case 2:
return string(argument0) + "nd";
case 3:
return string(argument0) + "rd";
default:
return string(argument0) + "th";
}``````
How to use it:
Code:
``````ordinalindicator(1);    // outputs: "1st"
ordinalindicator(2);    // outputs: "2nd"
ordinalindicator(3);    // outputs: "3rd"``````

S

#### Snayff

##### Guest
That's nice to know buddy, thank you. Not sure how often it would come up but when it does it would be super useful!

#### ClassyGoat

##### Member
I didn't even realize I needed this for my business management game until I saw this post.
Thanks!!!

#### gnysek

##### Member
Code:
``````/// @desc ordinalindicator(int) returns the int as a str with st, nd, rd or th at the end
/// @param integer
var s = ["st" ,"nd", "rd"], v = ((argument0 + 90) % 100-10) % 10;
return string(argument0) + ( (v and v <= 3) ? s[v-1] : "th");``````