_CAST
Jump to navigation
Jump to search
The _CAST pseudo-function performs a C-like cast of a numerical value to a specified numerical type.
Syntax
- result = _CAST(numericalType, numericalValue)
Parameters
- numericalType specifies the target type for the conversion.
- numericalValue is the value to be cast to the specified type.
Description
- _CAST allows explicit type conversion, similar to C-style casting.
- _CAST does not round the value like INT, _ROUND, CINT, or CLNG.
- The return type is determined by numericalType.
- A compiler error is thrown if numericalType is invalid or numericalValue is a STRING.
- No runtime errors are thrown if numericalType and numericalValue are valid.
Availability
Examples
- Example 1
- Basic type conversion.
DIM a AS DOUBLE DIM b AS _INTEGER64 a = 123.456 b = _CAST(_INTEGER64, a) PRINT "Original: "; a PRINT "Casted: "; b a = 456.789 b = _CAST(_INTEGER64, a) PRINT "Original: "; a PRINT "Casted: "; b a = -123.456 b = _CAST(_INTEGER64, a) PRINT "Original: "; a PRINT "Casted: "; b a = -456.789 b = _CAST(_INTEGER64, a) PRINT "Original: "; a PRINT "Casted: "; b |
Original: 123.456 Casted: 123 Original: 456.789 Casted: 456 Original: -123.456 Casted: -123 Original: -456.789 Casted: -456 |
- Example 2
- Type conversion function comparison.
PRINT 4.6!; INT(4.6!); FIX(4.6!); CLNG(4.6!); _ROUND(4.6!); _CAST(LONG, 4.6!) PRINT -4.6!; INT(-4.6!); FIX(-4.6!); CLNG(-4.6!); _ROUND(-4.6!); _CAST(LONG, -4.6!) PRINT 1%%; _CAST(_UNSIGNED _BYTE, 1%%) PRINT -1%%; _CAST(_UNSIGNED _BYTE, -1%%) |
4.6 4 4 5 5 4 -4.6 -5 -4 -5 -5 -4 1 1 -1 255 |
See also
- _CEIL
- INT, FIX
- CINT, CLNG,
- CSNG, CDBL
- _ROUND
- Variable Types
- Keyword Reference - Alphabetical
- Keyword Reference - By usage