Siebel eScript Language Reference > About Siebel eScript > About Data Types and Numbers >

How Siebel eScript Converts Data Types


Siebel eScript implicitly converts data types in many mixed-type contexts. You must use conversion methods to make sure your code does the required conversions. For more information, see Conversion Methods.

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.

Setting the Data Type Can Cause a Conversion

Siebel eScript does conversions differently depending on if the variable is typeless or strongly typed. For more information, see Using Strongly Typed and Typeless Variables.

How Siebel eScript Converts a Typeless Variable

If Siebel eScript sets the data type for a typeless variable, then it converts this variable only to another typeless variable. For example, the following examples result in Siebel eScript converting VariableA to a string:

var VariableA = 7.2;
var VariableB = "seven point 2"
VariableA = VariableB;

How Siebel eScript Converts a Strongly Typed Variable

Table 4 describes how Siebel eScript converts a strongly typed variable. In this table, assume that Siebel eScript must convert VariableA to VariableB.

Table 4. How Siebel eScript Converts a Strongly Typed Variable
VariableA Type
VariableB Type

 

Value
Chars
Bool
Float
Object
String
Number
Boolean
Other

Value

Same

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Chars

Yes

Same

Yes

Yes

Yes

Yes

Yes

Yes

Yes W

Bool

Yes

Yes

Same

Yes

Yes

Yes

Yes

Yes

Yes

Float

Yes

Yes, W

Yes

Same

Yes, W

Yes, W

Yes

Yes

Yes, W

Object

Yes

Err

Err

Err

Same

None

None

None

None

String

Yes

Yes

Err

Err

Err

Same

Err

Err

Err

Number

Yes

Err

Err

Yes

Err

Err

Same

Err

Err

Boolean

Yes

Err

Yes

Err

Err

Err

Err

Same

Err

Other

Yes

Err

Err

Err

Err

Err

Err

Err

Same

Table 4 uses the following abbreviations:

  • Yes. Siebel eScript converts the variable.
  • W. Siebel Tools might display a message when it compiles the script. This message warns that the conversion might not occur. The warning and conversion depend on the properties of the variables that are involved when Siebel eScript sets the data type.
  • Err. A compilation error occurs.
  • None. No conversion is required. A conversion is not typically required to modify an Object variable to a specialized object type.
  • Same. VariableA and VariableB are of the same type.
  • Value. Indicates a typeless variable. It describes the conversion that Siebel eScript does in the following situations:
    • Convert a strongly typed variable to a typeless variable.
    • Convert a typeless variable to a strongly typed variable.
  • Other. Indicates predefined types and custom types that are not the following types:
    • Object
    • String
    • Number
    • Boolean
Siebel eScript Language Reference Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.