Tech Tip: How to check if a value is a number
PRODUCT: 4D | VERSION: 2003 | PLATFORM: Mac & Win
Published On: March 25, 2004
Here's a method you can use to check if a text value is actually a number. This is useful if you are parsing a text file containing a variation of character of numerical strings.
` checks if all characters are numerical characters
C_TEXT($1;$char)
C_LONGINT($i)
C_BOOLEAN($isChar)
$isChar:=False
For ($i;1;Length($1))
If ($isChar)
$i:=Length($1)
Else
$char:=Substring($1;$i;1)
If ((Ascii($char)<48) | (Ascii($char)>57))
$isChar:=True
End if
End if
End for
` is it a character string?
$0:=Not($isChar)
Commented by Garry Lee on January 26, 2011 at 11:04 AM
if $char is an alphabet, Ascii($char) function won't return a numeric value. it returns the alphabet instead.