Search code examples
.netformattingdateordinals

Is there an easy way in .NET to get "st", "nd", "rd" and "th" endings for numbers?


I am wondering if there is a method or format string I'm missing in .NET to convert the following:

   1 to 1st
   2 to 2nd
   3 to 3rd
   4 to 4th
  11 to 11th
 101 to 101st
 111 to 111th

This link has a bad example of the basic principle involved in writing your own function, but I am more curious if there is an inbuilt capacity I'm missing.

Solution

Scott Hanselman's answer is the accepted one because it answers the question directly.

For a solution however, see this great answer.


Solution

  • No, there is no inbuilt capability in the .NET Base Class Library.