Type Conversion

To permit work with variables of different data types, Benchmark Description Language offers the following functions for converting data types:
Function Parameter Return value Description
ord character ASCII code Converts a single character to its ASCII value
chr ASCII code character Converts an ASCII value to its corresponding character value
string
  • integer
  • float
  • boolean
string Converts the value of an expression to a string
number
  • string
  • float
  • boolean
integer Converts the characters of a string or a floating-point value to an integer value. A boolean value is converted to 0 for invalid expressions (false) or 1 for valid (true) expressions.
float
  • string
  • integer
  • boolean
float Converts the characters of a string or an integer value to a floating-point value. A boolean value is converted to 0.0 for invalid expressions (false) or 1.0 for valid (true) expressions

Syntax

ConvertFunc = "chr" "(" Expr ")"
            | "ord" "(" Expr ")"
            | "string" "(" Expr ")"
            | "number" "(" Expr ")"
            | "float" "(" Expr ")"
            | "boolean" "(" Expr ")".
  • If number(string) cannot convert the string to a number, it returns zero (0).
  • If string contains a floating-point value, the digits after the decimal point are truncated.
  • If float(string) cannot convert the string to a floating-point number, it returns zero (0.0).

Alphanumeric characters after digits are ignored.

Example

dcltrans
  transaction TMain
  var
    I : number;
    f : float;
    s : string(14) init "ProductName";
    s1 : string(14);
    b1 : boolean;
  begin
    I := ord('x');          // --> i: 120
    s[1] := chr(I+1);       // --> s[1]: 'y'
    I := ord(s[2]);         // --> i: 114
    I := 123;
    s := string(I*10+1000); // --> s: "2230"
    I := number(s);         // --> i: 2230
    s := "-123.99";
    I := number(s);         // --> i: -123
    s := "123aby";
    I := number(s);         // --> i: 123
    s := "x123.99";
    I := number(s);         // --> i: 0
    s := "A" + string(I);   // --> s: "A0"
    s := "-129.77";
    f := float(s);          // --> f: -129.77
    I := 20500;
    f := float(I);          // --> f: 20500.0
    b1 := boolean("TRUE");  // --> b1: true
    s := string(b1);        // --> s: "TRUE"
    i := number(b1);        // --> i: 1
  end TMain;