CONVERT
The CONVERT script function converts the data type of a value. You can convert values specified directly or through a script variable. The function returns the value in the new data type. Assign the return code to a script 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
| Parameter | Format | Description |
|---|---|---|
| Data type | See allowed values |
Data type to which you want to convert the value. Allowed values:
Note: Specify the data type without quotation marks. |
| value | script literal or script variable |
Value whose data type you want to convert. Note: Enclose numbers in quotation marks. |
Examples
The following example converts a positive integer into a string.
:DEFINE &unsigned#, unsigned
:DEFINE &string#, string
:SET &unsigned# = 12
:SET &string# = CONVERT(string, &unsigned#)
The following example converts a string to a number. This conversion is possible because the string contains a number in a format valid for the target data type.
:DEFINE &unsigned#, unsigned
:DEFINE &string#, string
:SET &string# = "1234"
:SET &unsigned# = CONVERT(unsigned, &string#)
See also:
seealso