Mobile Line Of Business

Richard Jones (MVP)

  Home  |   Contact  |   Syndication    |   Login
  202 Posts | 0 Stories | 36 Comments | 0 Trackbacks

News

Welcome to the Mobile Line Of Business Blog

Tag Cloud


Archives

Post Categories

About

Need a quick .Net function to add ordinals to numbers?

Don’t know what an ordinal is (I didn’t).

Its numbers written like 1st 2nd 3rd etc.

Anyway here’s the function -

 

private string placelabel(int num)
       {
           switch (num % 100)
           {
               case 11:
               case 12:
               case 13:
                   return num.ToString() + "th";
           }

           switch (num % 10)
           {
               case 1:
                   return num.ToString() + "st";
               case 2:
                   return num.ToString() + "nd";
               case 3:
                   return num.ToString() + "rd";
               default:
                   return num.ToString() + "th";
           }

       }

posted on Monday, February 22, 2010 10:29 AM

Feedback

# re: Quick Ordinals 2/22/2010 12:52 PM Mark Pearl
Thanks Richard.. I never knew what ordinals were before!

Post A Comment
Title:
Name:
Email:
Comment:
Verification: