If the target variable has a different data type than a variable that is included in the calculation or assignment, a type conversion is performed.

Type conversion may be implicit or explicit. An implicit type conversion is performed when the target variable is a different numeric data type than the data types used in the expression. Implicit type conversion is available in the following cases:

  • When casting an integer type to another integer type
  • When casting a floating point type to another floating type

To force an explicit type conversion, place the expression to be converted in parenthesis. Write the target data type before the parenthesis.

variable =target type(assignment expression)

Example: Type Conversions

program
  int32 intVar1 = 10, intVar2 = 30
  real64 realVar1 = 0.5, realVar2 = 3.1415
  text textVar(10) = "5"

  realVar1 = real64( textVar ) + real64( textVar ) - realVar2
  realVar2 = real64( intVar1 + intVar2 ) * realVar1

  intVar1 = int32( realVar1 + realVar2 ) - int32( textVar )
  intVar2 = int32( textVar ) * intVar1

  realVar1 = text( intVar1 * intVar2 ) + text( realVar1 - real64( intVar1 ))
  realVar1 = text( sin( realVar1 ) )

endprogram