Typecasting of Expressions
Expressions have data types the same as variables. Expressions are automatically typecast according to the highest-order data type represented among the components of the expression.
Expression Typecasting, Highest to Lowest Order
- Real
- Date
- Number
- Integer
- String
- Boolean
Therefore, if an expression contains both Number and Integer components, the value of the expression will be Number. For example:
(5.0 / 2)
This expression will return the Number value 2.5 because one of the components (5.0) is written as a number. However:
(5 / 2)
This expression will return the Integer 2 because both components are written as integers. A more explicit way to return a Number answer of 2.5 would be:
(Number(5) / 2)
In this example, we are explicitly typecasting the 5 component using the Number function. However, the next example will still yield an answer of 2.0:
(Number(5 / 2))
The reason is that the sub-expression (5 / 2) is evaluated to an Integer result of 2 before the Number function is applied.