Author Topic: Add "st", "nd", "rd", "th"  (Read 2289 times)

Windlord

  • Guest
Add "st", "nd", "rd", "th"
« on: April 25, 2011, 04:37:00 am »
Code: (squirrel) [Select]
// This function returns 1st/2nd/3rd/4th from an integer
function GetNth ( num )
{
local lastdigs = num % 100;
switch ( lastdigs )
{
case 11: return num +"th"; // Catch out 11, 111
case 12: return num +"th"; // Catch out 12, 112
case 13: return num +"th"; // Catch out 13, 113
default: // Everything else should be normal...
lastdigs = num % 10; // Get last digit
switch ( lastdigs )
{
case 1: return num +"st";
case 2: return num +"nd";
case 3: return num +"rd";
default: return num +"th";
}
}
}
« Last Edit: May 05, 2011, 05:59:16 pm by Windlord »

Windlord

  • Guest
Re: Add "st", "nd", "rd", "th"
« Reply #1 on: May 05, 2011, 06:00:03 pm »
Thanks to Mike for pointing it out:

Now GetNth returns 111th, 11th, 112th, 12th, 113th, and 13th
instead of 111st, 11st, 112nd, 12nd, 113rd, 13rd.

 

© Liberty Unleashed Team.