Adding Ordinal Indicators to numbers (1st, 2nd, 3rd, 4th etc) in GameMaker

Heres a quick snippet of code for GameMaker that adds 'st', 'nd', 'rd' or 'th' to the end of an integer.

Those letters after the number are called their ordinal because they show the order of the value rather than a cardinal number which shows the quantity of something.

This is great if you are doing score boards or working out the winner of a race.

Add this code into a script called ordinalindicator:
/// 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";
        return string(argument0) + "th";
Usage Example:
ordinalindicator(0);	// outputs: "0"
ordinalindicator(1);	// outputs: "1st"
ordinalindicator(2);	// outputs: "2nd"
ordinalindicator(3);	// outputs: "3rd"
ordinalindicator(4);	// outputs: "4th"
ordinalindicator(5);	// outputs: "5th"
ordinalindicator(6);	// outputs: "6th"
ordinalindicator(10);	// outputs: "10th"
ordinalindicator(11);	// outputs: "11th"
ordinalindicator(12);	// outputs: "12th"
ordinalindicator(13);	// outputs: "13th"
ordinalindicator(14);	// outputs: "14th"
ordinalindicator(22);	// outputs: "22nd"
ordinalindicator(23);	// outputs: "23rd"
ordinalindicator(100);	// outputs: "100th"
ordinalindicator(101);	// outputs: "101st"
ordinalindicator(152);	// outputs: "152nd"
ordinalindicator(293);	// outputs: "293rd"
ordinalindicator(30004);// outputs: "30004th"
ordinalindicator(55555);// outputs: "55555th"

Normally you would want this to be done in superscript smaller text to the side. And it wouldn’t be so difficult to convert the script to do this. In the script I return argument0 along with the letters, all you would need to do is remove this and just draw them in two separate functions.

It’s also worth knowing that different languages have different endings however it should be easy enough to adapt the code to replace the English strings I have used with different endings. Occasionally some languages group theirs up differently, however it would take me too long to go through and do one for each In French they can use different letters depending on the gender of the word and in German they just put a dot at the end of all ordinal numbers.

About the Article:
Easy Difficulty
By David Strachan