Javascript Number ordinal()
Number.prototype.ordinal = function () { return this + ( (this % 10 == 1 && this % 100 != 11) ? 'st' : (this % 10 == 2 && this % 100 != 12) ? 'nd' : (this % 10 == 3 && this % 100 != 13) ? 'rd' : 'th' );/*from www. j av a2 s .c o m*/ }
// Return the ordinal of the given number // (1).ordinal() returns "st" (as in 1st) // (2).ordinal() returns "nd" (as in 2nd) Number.prototype.ordinal = function() { var s = ["th", "st", "nd", "rd"], v = this % 100; return (s[(v - 20) % 10] || s[v] || s[0]); };