Get Ordinal Suffix of a Number


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static string[] SuffixLookup = { "th","st","nd","rd","th","th","th","th","th","th" };
  2.  
  3. public static string AppendOrdinalSuffix(int number)
  4. {
  5. if (number % 100 >= 11 && number % 100 <= 13)
  6. {
  7. return number + "th";
  8. }
  9. return number + SuffixLookup[number% 10];
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.