Script function: Converts the data type of a value.
CONVERT (Data type, value)
Syntax |
Description/Format |
---|---|
Data type |
Data type to which conversion is required. unsigned: positive integers without signs Data types are indicated without inverted commas. |
Value |
Value whose data type should be converted to a different data type. Format: script literal or script variable Numbers must also be specified in inverted commas. |
Return code |
---|
Value including the converted data type. |
This script function can be used to convert the data type of a value that has been specified directly or via a script variable to a different data type. The return code is the converted value which must be assigned to a target variable.
Ensure that the data type of the value that should be converted complies with the target variable's data type when you use this script function.
Strings can only be converted to numbers if the string includes a number in a valid format.
Attempts to convert a higher number type to a lower one have the effect that decimal numbers are rounded or signs are removed.
Conversion is not possible if the target variable's data type does not comply with the function's parameter "Data type". The result is a scripting error.
Note that you cannot convert negative numbers with this script function
The first example converts a positive integer into a string.
:define &unsigned#, unsigned
:define &string#, string
:set &unsigned# = 12
:set &string# = CONVERT(string, &unsigned#)
The second example converts a string to a number. This is only possible if the string consists of a number that has a valid format for the target data type.
:define &unsigned#, unsigned
:define &string#, string
:set &string# = "1234"
:set &unsigned# = CONVERT(unsigned,&string#)
See also:
Script Elements - Editing Objects
About Scripts
Script Elements - Alphabetical Listing
Script Elements - Ordered by Function