Forum Moderators: open
A couple of scripts that I've found are:
[javascriptkit.com...]
Thanks a million. Spent a while trying to solve the conundrum myself, but my Javascript skills are limited.
function NumberSuffix(What) {
if (isNaN(What)) { return ''; } // non-numeric
var NS_String=String(What);
var NS_Length=NS_String.length;
if (NS_Length == 0) { return ''; } // nothing to do
if (NS_Length > 1) {
var NS_Item=NS_String.substring(NS_Length-2,NS_Length-1);
if (NS_Item == 1) { return 'th'; } // teens
}
var NS_Item=NS_String.substring(NS_Length-1);
if (NS_Item == 1) { return 'st'; } // firST
if (NS_Item == 2) { return 'nd'; } // secoND
if (NS_Item == 3) { return 'rd'; } // thiRD
return 'th'; // all others
}