Menu

test for numeric

Developers
2007-07-30
2012-08-14
  • Nobody/Anonymous

    Is there an easy test whether a value is numeric? (to avoid accepting a 'O' for '0',eg)

    --Gary

     
    • Nobody/Anonymous

      Correction:

      The function name should read verify() not validate().

      Sorry
      J.Peelen

       
    • Rick McGuire

      Rick McGuire - 2007-07-30

      Try

      value~datatype('N')
      

      If you wish to test for a numeric value. If you're looking for an integer value, then

      value~datatype('W')
      

      is what you're looking for. Either one will return "1" (true) if the value is valid, or "0" (false) if it doesn't pass.

      Rick

       
    • Nobody/Anonymous

      Thanks Rick

      --Gary

       
    • Nobody/Anonymous

      Note some pitfalls here:

      Datatype(N) as well as datatype(W) recognize a string like '0E00' as numeric. I fell into this trap on a mainframe with a DASD address like that. '0E00' is taken as a valid exponential notation for zero.

      Datatype(W) also recognizes '1.000' as whole number.

      If I want to test for figures only (like: 123), I use validate().

      J.Peelen

       

Log in to post a comment.