Ordinals with Number.prototype extension

Number.prototype.toOrdinal()

/*  (c) APV, Artistic License 2, retain this notice  */

Number.prototype.toOrdinal = function () {
  var i = this.toString();
  if ( i.match(/\D/) ) return i;
  if ( i == 3 || i.match(/[^1]3$/) ) return i + 'rd';
  if ( i == 2 || i.match(/[^1]2$/) ) return i + 'nd';
  if ( i == 1 || i.match(/[^1]1$/) ) return i + 'st';
  return i + 'th';
}

Test script

<script type="text/javascript">//<![CDATA[
// import or include the above class prototype extension first
for ( var n = 0; n <= 150; n++ ) {
  document.write( n.toOrdinal() );
  if ( n != 150 ) document.write(' · ');
//]]></script>

Output

digg stumbleupon del.icio.us reddit Fark Technorati Faves
Your information (required) Name*
Email*
Website

* Indicates required fields; email is used for validation and is not displayed on the site.

Your comment
Commenting on Ordinals with Number.prototype extension
Title

Body is limited to ≈1,000 words. Paragraphs—but not line breaks—are automatically inserted. Valid XHTML is required. These are the allowed tags–

<a href=""></a> <br/> <acronym title=""></acronym> <abbr title=""></abbr> <code></code> <pre></pre> <tt></tt> <ins></ins> <del></del> <hr/> <cite></cite> <b></b> <i></i> <sup></sup> <sub></sub> <strong></strong> <em></em> <h1></h1> <h2></h2> <h3></h3> <q></q> <blockquote></blockquote>