/ Published in: JavaScript
1 -> 1st, 2 -> 2nd ...
Expand |
Embed | Plain Text
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' ); }
Comments
Subscribe to comments
You need to login to post a comment.

A really good definition for this function is found on Chris West's blog at http://gotochriswest.com/blog/2012/09/28/javascript-number-getordinalfor/.