$Vnum

From m204wiki
Jump to navigation Jump to search

The $VNUM function returns a 1 if the given argument is in a valid format for a SORT BY VALUE NUMERICAL statement or for any type of mathematical operation. To be valid, the first argument must be a decimal number with optional sign. Leading or trailing blanks, or blanks between the sign and the number, are ignored. If the contents of the argument do not have the required form, 0 is returned. Numeric values with more than 63 significant digits are not in the correct form; a 0 is returned.

Syntax

$VNUM(numeric-string-value{,'SORT' | 'SORTKEY' | 'FLOAT' | 'BINARY'})

Where:

  • SORTKEY returns 1 if the numeric value is valid as a numeric string sortkey. See NUMERICAL option. A numeric string sortkey value that is not acceptable to $VNUM as a SORTKEY value is sorted in character order even if the SORT statement specifies numeric order.
  • The following compression rules apply to SORTKEY:

Leading plus (+) or minus (-) sign is compressed.

Leading blanks before and after the (optional) leading +/- sign are compressed.

Leading zeros after the (optional) leading +/- sign and blanks are compressed.

1-63 integer digits before the (optional) decimal point are allowed.

Values greater than -1 and less than 1 require leading "0.nnn".

Optional decimal point and fractional value are allowed.

Trailing blanks are compressed.

1-253-byte total length is allowed.

  • 'FLOAT' returns 1 if the numeric value is valid as an E-format floating point numeric string.
  • 'BINARY' returns 1 if the numeric value is valid as a compressible binary value (to be stored in a BINARY NON-CODED field). See Storing values in BINARY fields. Otherwise returns a 0.
  • The following compression rules apply to BINARY:

1-9 decimal integer values are allowed.

No leading zeros are compressed.

Leading plus (+) sign is compressed.

Leading minus (-) sign is allowed.

Example 1

$VNUM(' + 256.73 ') equals 1 $VNUM('14') equals 1 $VNUM('-17.17') equals 1 $VNUM('.1794763') equals 1

Example 2

$VNUM(' -256.73 AB') equals 0 $VNUM('256.73-') equals 0 $VNUM(' TWELVE') equals 0

Example 3

This example averages premium amounts. The amounts are included in the average only if they meet the $VNUM specifications.

BEGIN %CT IS FLOAT GET.RECS: FIND ALL RECORDS END FIND FOR EACH RECORD IN GET.RECS IF $VNUM(TOTAL PREMIUM) THEN %TOT = %TOT + TOTAL PREMIUM %CT = %CT + 1 END IF END FOR %AVERAGE = %TOT/%CT PRINT 'THE AVERAGE PREMIUM IS ' - WITH '$' WITH %AVERAGE END