Skip to content

Instantly share code, notes, and snippets.

@jondwx
Created November 4, 2017 00:48
Show Gist options
  • Save jondwx/cf68e4b5c58a47e05e2c7bb1aa2bb468 to your computer and use it in GitHub Desktop.
Save jondwx/cf68e4b5c58a47e05e2c7bb1aa2bb468 to your computer and use it in GitHub Desktop.
Number to Ordinal Format
function numberToOrdinal(i) {
var j = i % 10,
k = i % 100;
if (j == 1 && k != 11) {
return i + "st";
}
if (j == 2 && k != 12) {
return i + "nd";
}
if (j == 3 && k != 13) {
return i + "rd";
}
return i + "th";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment