|
|
|
| 21 August 2002 | Ordinal() |
| Author | ScriptLogic Corporation |
| Action | Takes a number and returns the named series of that number (e.g.: 1st, 2nd, 53rd, 89th, etc.). |
| Syntax | Ordinal (number) |
| Parameters | |
| Remarks | Special thanks to Joe Burke for pointing out the "1 as next-to-last character exception issue" and Alex Peters for suggesting an appropriate name for this UDF :) |
| Returns | The ordinal in string form. |
| Dependencies | None. |
| Examples | ?'Today is '+@day+' '+@Month+' '+Ordinal(@MDayNo)+', '+@Year+'.' |
| Source |
FUNCTION Ordinal ($expr)
;returns the ordinal of a given number in string form
;examples: 1=1st, 2=2nd, 3=3rd, 4=4th ... 110th
DIM $lastchar
$expr=''+$expr ; cast string
IF (Len($expr) > 1) AND (Left(Right($expr,2),1) = '1')
; '1' as next to last character is exception
$ordinal=$expr+'th'
ELSE
$lastchar=Substr($expr,Len($expr),1)
SELECT
CASE ($expr = '0')
$ordinal='0'
CASE ($lastchar = '1')
$ordinal=$expr+'st'
CASE ($lastchar = '2')
$ordinal=$expr+'nd'
CASE ($lastchar = '3')
$ordinal=$expr+'rd'
CASE 1
$ordinal=$expr+'th'
ENDSELECT
ENDIF
ENDFUNCTION ; - Ordinal -
|
|
|
|