CONVERT
Use the CONVERT script function to convert the data type of a value. The script function lets you convert values that have been specified directly, or through a script variable. The script function returns the value with the converted data type. Assign the return code of the script function to a variable to use the converted value.
Important! Ensure that the data types match, as mismatches can cause errors:
- The data type of the value you want to convert must match the data type of the target variable.
- The data type you specify in the script function must match the data type of the target variable.
Notes:
- You can only convert a string to a number if the string consists of a number in a format that is valid for the target variable.
- When you convert a higher number type to a lower one, decimal numbers are rounded, and signs are removed.
- You cannot convert negative numbers with this script function.
Syntax
CONVERT (Data type, value)
Parameters
-
CONVERT
Converts the data type of a value -
Data type
Data type to which you want to convert the value
Allowed values:- unsigned
positive integers without signs - signed
integers with signs - float
floating-point number - string
string, text
- unsigned
-
value
Value whose data type you want to convert
Format: script literal or script variable
Note: Enclose numbers in quotation marks.
Example
The following script converts a positive integer into a string.
:define &unsigned#, unsigned
:define &string#, string
:set &unsigned# = 12
:set &string# = CONVERT(string, &unsigned#)
The following script converts a string to a number. This conversion is possible because the string in the example consists of a number in a format that is valid for the target data type.
:define &unsigned#, unsigned
:define &string#, string
:set &string# = "1234"
:set &unsigned# = CONVERT(unsigned,&string#)
See also:
seealso