Siebel eScript Language Reference > Siebel eScript Language Overview > Data Types in Siebel eScript >
Implicit Type Conversion in Siebel eScript
Siebel eScript performs implicit data type conversion in many mixed-type contexts. However, to make sure that your code performs conversions as you expect it to, you should use conversion functions that are provided for that purpose, and you should test your code prior to putting it into production.
For more information on conversion methods, see Conversion Methods.
The rules governing run-time conversion of data types vary and depend on:
- Whether the type mismatch is in the context of a value assignment or the result of concatenation
- Whether the variables involved are typeless or strongly typed
Implicit Type Conversion Resulting from Concatenation in eScript
Data type conversion of typeless variables occurs implicitly 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 implicit conversions:
s = "dog" + "house" // s = "doghouse", two strings are concatenated.
t = "dog" + 4 // t= "dog4", a number is converted to a string
u = 4 + "4" // u = "44", a number is converted to a string
v = 4 + 4 // v = 8, two numbers are added
w = 23 - "17" // w = 6, a string is converted to a number
To make sure that type conversions are performed when doing addition, subtraction, and other arithmetic, use conversion methods. The following example uses a conversion method to transform string input to numeric to perform arithmetic:
var n = "55";
var d = "11";
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 convert data to specific types. Some of these are not part of the ECMAScript standard.
NOTE: There are circumstances under which conversion is not performed implicitly. If you encounter such a circumstance, you must use one of the conversion functions to get the desired result. For an explanation of conversion functions, see Conversion Methods.
Implicit Type Conversion Resulting from Assignment in eScript
Implicit type conversion resulting from assignment differ for typeless and strongly typed variables.