A: After quite some optimisation, you could end up with a function looking something like this:
Code:
Number.prototype.toOrdinal=function(m){
return (this +
["th","st","nd","rd"][(!(
((m=this%10) >3) ||
(Math.floor(this%100/10)==1)
))*m]);
}
and you use it like this:
Code:
var
nNumber=12,
sFirstOrdinal=nNumber.toOrdinal(), // => '12th'
sSecondOrdinal=(22).toOrdinal(); // => '22nd'
Well, I won't bore you with the development procedure of this very slick and optimised function. You can check it out yourself in
this thread.