I am trying to display numbers within a particular table with ordinal suffixes. The table always shows three numbers which come from an XML file. The numbers show ranks, so for
function nth(n){ if(isNaN(n) || n%1) return n; var s= n%100; if(s>3 && s<21) return n+'th'; switch(s%10){ case 1: return n+'st'; case 2: return n+'nd'; case 3: return n+'rd'; default: return n+'th'; } }
You can take care of the teens in their own line, other integers follow the last digit rules.