Posted By

kif on 08/16/06


Tagged

number ordinal


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

johnloy


Ordinal Number


 / Published in: JavaScript
 

1 -> 1st, 2 -> 2nd ...

  1. Number.prototype.ordinal = function () {
  2. return this + (
  3. (this % 10 == 1 && this % 100 != 11) ? 'st' :
  4. (this % 10 == 2 && this % 100 != 12) ? 'nd' :
  5. (this % 10 == 3 && this % 100 != 13) ? 'rd' : 'th'
  6. );
  7. }

Report this snippet  

You need to login to post a comment.