Skip to content

Instantly share code, notes, and snippets.

@jmcd
Created May 8, 2012 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcd/2633365 to your computer and use it in GitHub Desktop.
Save jmcd/2633365 to your computer and use it in GitHub Desktop.
Ordinal suffix of an integer
public static class IntExtensions
{
public static string GetOrdinalSuffix(this int @this)
{
switch (@this % 100)
{
case 11:
case 12:
case 13:
return "th";
default:
switch (@this % 10)
{
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment