Javascript Number toOrdinal()

Description

Javascript Number toOrdinal()


Number.prototype.toOrdinal = function() {
 var n = this % 100;
 var suffix = ["th", "st", "nd", "rd", "th"];
 var ord = n < 21 ? (n < 4 ? suffix[n] : suffix[0]) : (n % 10 > 4 ? suffix[0] : suffix[n % 10]);
 return this + ord;
};



PreviousNext

Related