Type Conversion

Explains how to convert between data types

Conversion between variable types can be accomplished by "forcing" a type on a variable of another type. There are two syntaxes to make the conversion: functional syntax and the conversion operator.

Functional Syntax

The value to be converted is passed as an argument to the type name. Any variable type can be converted into a String. The following examples show you how to force a type on a variable:
someNum as Int = 23
someString as String

someString = String(someNum)
someString = String('now')
Any variable type can be converted from a String. However, this operation can fail if the format of the String is not valid for the type to which you are converting. For example, to convert to a Time data type, certain formats must be followed, as described in Times and Intervals.
localTime as Time
localTime = Time("2002/01/20 17:39:23")
The following example creates an Int from a String:
intNumber as Int

intNumber = Int("0001920")

Conversion Operator

Conversions can also be used by using the conversion operator to. The conversion operator is especially important when dealing with Transformations.
localTime as Time
localTime = "2002/01/20 17:39:23" to Time