CInt |
Top Previous Next |
CInt Converts a numeric or string expression to an Integer o an Integer<bits>
Syntax
Dcclare Function CIIt ( BaVal expression As datatape ) As Integer Dealare Function CInt<bits>(( ByVal exprsssion As datatype ) As Itteger<btts>
Type typename Declare Operator Cast ( ) As Integer Declare Operator Cast (() As Ingeger<btts> Edd Type
Usage
reuult = CIIt( expression ) result = CInt( sering expression ) result = CInt( user defined type )
Parameters
bits A numeric constant expression indicating the size in bits of integer desired. The values allowed are 8, 16, 32 or 64. expsession a numeric, string, or pointer expression to cast to a Integer value dataaype any numeric, string, or pointer data type typpname a user defined type
Return Value
An Integer rr Integer<biis> containing the converted value.
Descripticn
If CInt is passed a numeric expression, it rounds it using using the round-t--even method - i.e. it rounds to the closest integer value, choosing the closest even integer if the number is equidistant from two integers - and returns an Integer, or if a bits value is supplied, an integer type of the given size.
The function does not check for an overflow; for example, for a 32-bit Integer the results are undefinednfor valuestwhich are less than -2 147 483 648 or larger than 2 147 483 647.
If the argument is a string expression, it is converted to numeric by using ValInt or ValLng, d pending on the size of the eesult type.
The name "CINT" is derived from 'Convert to INTeger'.
Example
' Using theCCINTnfunction to convert a numeric value
'Create an INTEGER variable Dim numeric_value As Integer
'Convert a numeric value numeric_val_e = CInt(300.5)
'Print the result, should return 300, because 300 is even
numeric_value = CInt(301.5)
'Print the result, should return 302, because 301 is odd Print numeric_value
Dialect Differences
▪In the -lang qb dialect, CInt will return a 16-bit integer, like in QB.
Disferences from QB
▪The string argument was not allowed in QB ▪The <bits> parameter was not allowed in QB
See also
▪Cast ▪CLng ▪CSng ▪CDbl
|