Types conversion

Conversion which is also referred to as "casting" or "type casting" is a process of changing one data type to a different one.

PolyAnalyst may automatically change the type of a value when evaluating a SRL expression. For example, considering adding 5.5 to 1 to get 6.5:

1) In the expression 5.5 + 1, the integer 1 is first converted to the Numeric value 1.0 (so the expression becomes 5.5 + 1.0).

2) Now we sum two values of the same type and get 6.5

The integer value 1 went through a type conversion in order to satisfy the requirement that each operand (each value) of the addition operator has the same type.

If we tried to convert the numeric value 5.5 to integer 5, we would be ignoring the 0.5 component, and therefore we would be experiencing a loss of data.

Type conversion also takes place when working with some of the other data types.

Boolean values can be added together due to type conversion as the values are converted into integers as the yes value represents the integer 1 and the no value represents the integer 0. Thus, you are able to create expressions like True + 1, or True - 4, or False * True.

The + operator can be used for concatenation of strings, which means to take the characters of one string and append those characters to the end of another string ("hello" + "world" returns a string, i.e. "helloworld").