Clean Numeric String

CleanNum

The CleanNum procedure filters a character field by stripping out any non numeric characters. It also compresses and embedded blanks that may exist in the variable.

By default, the digits 0 to 9, a U.S. decimal notation (.) and the minus symbol (-) are retained

packed-decimal-value CleanNum(
  szSrcValue     256A   Const Varying
  szSaveChar      30A   Const Varying OPTIONS(*NOPASS)
)

See also: CharToNum, NumToZoned, NumToChar

Parameters

szSrcValue
[input VChar(256) const]  A varying or fixed-length character field whose length is 1 to 256 bytes. The data in the field should be number. Any non-numeric characters detected in the value specified for this parameter will be deleted. For example:

  Original Value

Cleaned Up Value
'12,345.60 CR' '12345.60'
'<<12345.60>>' '12345.60'
'(( 12,345,678 ))' '12345678'
szSaveChars [optional]
[input VChar(30) const]  An optional literal value that identifies additional characters that should not be filtered by the clean up routine. For example, you may want to retain commas or a currency symbol.

This parameter overrides the minus sign and decimal notation symbols ( - and . ). If you specify a value for this parameter and need the minus sign and decimal point retained, you must include them in the list of characters specified for this parameter. Specify additional characters to save when the value is filtered.
 

Return Value

If the function succeeds, the return value is a character string that has only valid numeric data stored in it.

If the function fails, the return value is empty.

Remarks

This procedure is provided primarily for CGI and EDI applications that need to process all data as text.

Example

.....DName+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++++++++++
     D szWebData       S             12A   Inz('<<1,321.50>>')
     D nBid            S              7P 2
     
     C                   Eval      szWebData = CleanNum(szWebData)

Before the CleanNum() procedure runs, the szWebData field contains:  '<<1,321.50>>'

After the CleanNum() procedure runs, the szWebData field contains:  '1321.50'