I hope someone else has something less clunky. I couldn't even think of a good name for the function
Code:
function num_abbrev_str(num) {
var len = num.length, last_char = num.charAt(len - 1), abbrev
if (len == 2 && num.charAt(0) == '1') {
abbrev = 'th'
} else {
if (last_char == '1') {
abbrev = 'st'
} else if (last_char == '2') {
abbrev = 'nd'
} else if (last_char == '3') {
abbrev = 'rd'
} else {
abbrev = 'th'
}
}
return num + abbrev
}
alert(num_abbrev_str('22'))