scripting@wanadoo.nl




Ordinal()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
21 August 2002 Ordinal()
AuthorScriptLogic Corporation
Action Takes a number and returns the named series of that number (e.g.: 1st, 2nd, 53rd, 89th, etc.).
SyntaxOrdinal (number) 
Parameters
  • number (Required / Numeric) The number that you want the suffix added to. 
  • RemarksSpecial 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 :) 
    ReturnsThe ordinal in string form. 
    DependenciesNone. 
    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 -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter