Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Number to 1st, 2nd, 3rd or First, Second, Third
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00931326
Message ID:
00931784
Views:
27
>Well, that's a start for now. It's hard to believe noone has been any farther than 31 so far. Thanx though!

Paul,

I think something like this should work for all numbers:
PROCEDURE NumSuffix
LPARAMETERS iNumber

LOCAL iElement, ;
      iLastDigit, ;
      cNumberString, ;
      aSuffixes(4), ;
      iTestNumber, ;
      i
      
aSuffixes[1] = "st"
aSuffixes[2] = "nd"
aSuffixes[3] = "rd"
aSuffixes[4] = "th"

iTestNumber = IIF(iNumber > 100, VAL(RIGHT(ALLTRIM(STR(iNumber)), 2)), iNumber)

cNumberString = ALLTRIM(STR(iNumber))
iLastDigit = VAL(RIGHT(cNumberString, 1))

** Use first 3 array elements if number ends in 1-3 without ending in 11-13
IF (INLIST(iLastDigit, 1, 2, 3) .AND. ;
    (! BETWEEN(iTestNumber, 11, 13)))
      
   iElement = iLastDigit

ELSE
   
   iElement = 4
         
ENDIF 

RETURN (cNumberString + aSuffixes[iElement])
I didn't go through an insane amount of testing but feel free to give it a whirl.

Laterness,
Jon
Jon Rosenbaum
Devcon Drummer
Previous
Reply
Map
View

Click here to load this message in the networking platform