AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() Or better yet, as an extension method public static class IntegerExtensions If (num.ToString().EndsWith("3")) return "rd" If (num.ToString().EndsWith("2")) return "nd" If (num.ToString().EndsWith("1")) return "st" If (num.ToString().EndsWith("13")) return "th" If (num.ToString().EndsWith("12")) return "th" If (num.ToString().EndsWith("11")) return "th" Simple, clean, quick private static string GetOrdinalSuffix(int num) Public void Ordinal_ReturnsExpectedResults() Negative and zero have no ordinal representation Public static string Ordinal(this int number) / Ordinal value of positive integers, or if less than 1. / Only works for english-based cultures. / Get the ordinal value of positive integers. Included unit test to show that the accepted answer is incorrect when number My version of Jesse's version of Stu's and samjudson's versions :)
0 Comments
Read More
Leave a Reply. |