Posted By

duncanmcdougall on 10/03/10


Tagged

int


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Get Ordinal Suffix of a Number


 / Published in: C#
 

  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  

You need to login to post a comment.