Siebel eScript Language Reference > Siebel eScript Language Overview > Data Types in Siebel eScript >

Automatic Type Conversion in Siebel eScript

Conversion occurs automatically during concatenation involving both strings and numbers, and is subject to the following rules:

  • Subtracting a string from a number or a number from a string converts the string to a number and performs subtraction on the two values.
  • Adding a string to a number or a number to a string converts the number to a string and concatenates the two strings.
  • Strings always convert to a base 10 number and must not contain any characters other than digits. The string "110n" does not convert to a number because the n character is meaningless as part of a number in Siebel eScript.

The following examples illustrate these automatic conversions:

"dog" + "house" == "doghouse" // two strings are joined
"dog" + 4 == "dog4" // a number is converted to a string
4 + "4" == "44"// a number is converted to a string
4 + 4 == 8   // two numbers are added
23 - "17" == 6   // a string is converted to a number

However, to make sure that your code does not break if the conversion is not performed, use one of the casting functions to perform the appropriate conversion. (For details on these functions, read Conversion or Casting Methods.) The following example accepts string input and converts it to numeric to perform arithmetic:

var n = "55";
var d = "11";
divide it by:");
var division = Clib.div(ToNumber(n), ToNumber(d));

To specify more stringent conversions, use the parseFloat() Method of the global object. Siebel eScript has many global functions to cast data as a specific type. Some of these are not part of the ECMAScript standard. Read parseFloat() Method.

NOTE:  There are circumstances under which conversion is not performed automatically. If you encounter such a circumstance, you must use one of the casting functions to get the desired result. For an explanation of casting functions, read Conversion or Casting Methods.

Siebel eScript Language Reference