We Recommend

ASP.NET 3.5 Unleashed ASP.NET 3.5 Unleashed
ASP.NET 3.5 Unleashed is the most comprehensive book available on the Microsoft ASP.NET 3.5 Framework, covering all aspects of the ASP.NET 3.5 Framework--no matter how advanced.


Posted By

Scooter on 05/19/08


Tagged


Versions (?)


Ordinal Numbers


Published in: ASP 


URL: http://reusablecode.blogspot.com/2008/04/ordinal-numbers.html

  1. <%
  2. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Returns the ordinal of a cardinal number.
  10. function ordinal(ByVal cardinal)
  11. cardinal = CStr(cardinal)
  12.  
  13. if Right(cardinal, 1) = "1" and Right(cardinal, 2) <> "11" then
  14. ordinal = cardinal & "st"
  15. elseif Right(cardinal, 1) = "2" and Right(cardinal, 2) <> "12" then
  16. ordinal = cardinal & "nd"
  17. elseif Right(cardinal, 1) = "3" and Right(cardinal, 2) <> "13" then
  18. ordinal = cardinal & "rd"
  19. else
  20. ordinal = cardinal & "th"
  21. end if
  22. end function
  23.  
  24. ' Unit test
  25. 'for i = 0 to 25
  26. ' Response.Write "<p>" & ordinal(i) & "</p>"
  27. 'next
  28. %>

Report this snippet 

You need to login to post a comment.