aRAD function: val

A RAD function that converts a datum to a different data type.

Function

val

Format

$new.data=val($data, $new.type)

Parameters

The following parameters are valid for the val function:

Parameter Data type Description
$data Any data type Datum to be converted.
$new.type Number Data type to convert the data to. The default value is one (1). For a list of the numbers that correspond to the data types, see Data types.

Factors

  • A number can be converted to date and time, a string, or logical.
  • A string can be converted to a number, date and time, or logical.
  • A date and time can be converted to a number or a string.
  • Logical can be converted to a number or a string.

Examples

The following examples show the value after execution:

Variable Value of $x after execution
$x=val(100) 100
$x=val(100, 2) "100"
$x=val(100, 3) ‘00:01:40’
$x=val(0, 4) false
$x=val(1, 4) true
$x=val(2, 4) unknown
$x=val(3, 4) NULL
$x=val("HP", 1) NULL
$x=val("100.3", 1) 100.3
$x=val("HP", 2) "HP"
$x=val("HP", 3) NULL
$x=val("2/15/96", 3) ‘02/15/96 00:00:00’
$x=val("true", 4) true
$x=val("0", 4) NULL
$x=val(‘01:00:23’, 1) 3623
$x=val(‘02/16/96 08:00:00’) 62992915200
$x=val(‘01/01/96’, 2) “01/01/96 00:00:00”
$x=val(‘02/09/96 08:00:00’, 3) ‘02/09/96 08:00:00’
$x=val(‘01/01/96’, 4) NULL
$x=val(‘12:34:56’, 4) NULL
$x=val(false) 0
$x=val(true, 1) 1
$x=val(unknown, 1) 2
$x=val(false, 2) "false"
b NULL
$x=val(unknown, 4) unknown