Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Number to 1st, 2nd, 3rd or First, Second, Third
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00931326
Message ID:
00931784
Vues:
30
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform