Concatenation Can Cause a Conversion

Siebel eScript converts the data type of a typeless variable in the following situations:

  • If you write Siebel eScript code that subtracts a string from a number, or that subtracts a number from a string, then it converts this string to a number and subtracts the two values.

  • If you write Siebel eScript code that adds a string to a number, or that adds a number to a string, then it converts this number to a string and concatenates the two strings.

Siebel eScript must always convert a string to a base 10 number. This string must contain only digits. For example, the following string does not convert to a number because Text is meaningless as part of a number in Siebel eScript:

110Text

The following examples result in Siebel eScript doing a conversion:

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

Using a Conversion Method

You must use a conversion method to make sure Siebel eScript does conversions when it adds, subtracts, or does other arithmetic operations. The following example uses a conversion method to convert a string input to a numeric value:

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

Use can use the parseFloat method of the global object to specify a more stringent conversion. For more information, see Convert String to Floating-Point Number Method.

You must use a conversion method in situations where Siebel eScript does not do a conversion. Siebel eScript includes many global methods that convert data types. For more information, see Conversion Methods.