Skip to content

Instantly share code, notes, and snippets.

@SaymV
Created June 21, 2013 18:51
Show Gist options
  • Save SaymV/5833429 to your computer and use it in GitHub Desktop.
Save SaymV/5833429 to your computer and use it in GitHub Desktop.
JavaScript Ordinal Number Display
var ordinalNumberDisplay = function (number) {
var suffixes = ["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"];
switch (number % 100) {
case 11:
case 12:
case 13:
return number + "th";
default:
return number + suffixes[number % 10];
}
};
alert(ordinalNumberDisplay(33)); //Alerts '33rd'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment