ID:195042
 
//Title: Ordinal Numbering
//Credit to: Admin at PHPSnips.com
//Modified by: Xooxer@Gmail.com (ported to DM)
//Contributed by: Xooxer
//Based from: PHP Snippet ordinal() (by user "Admin")


/*
This function takes a number, and returns a text string of the number with
its appropriate ordinl extension. If no number is provided, or the value
passed is not a valid number, the proc will return null, otherwise, it will
send back the number and its extension as text.

Args:
num - A signed numeral

Returns:
A text string containing the number nd its extension, or null if no valid
number was passed to the proc.

Example:

mob/verb/OrderPint()
if(drunk_pints > 4)
var/ord = num2ord(drunk_pints+1)
usr << "Bartender: This is your [ord] pint. Maybe you should slow down."
*/





proc
num2ord(num)
if(isnum(num))
.= "[num]"
var
abs_num = abs(num)
disabledes_digit = abs_num % 10
tens = abs_num%100
extension = ((tens < 21 && tens > 4) ? "th":
((ones_digit < 4) ? \
(ones_digit < 3) ? \
(ones_digit < 2) ? \
(ones_digit < 1) ? \
"th" : "st" : "nd" : "rd" : "th"))
.+= extension




///*
//Testing Code/Sample Implementation:

mob/verb/Test_num2ord()
var/i
for(i = 1 to 100)
usr << num2ord(i)

//*/
Heh. Don't get ticked at me, but have you tried the following?

usr << "[num]\th"
In response to Jtgibson (#1)
I never actually used this. I just came cross it and said, neato. >.>