CInt function
Returns an expression that has been converted to a Variantof the Integer subtype.
CInt(expression)
The expression parameter is any valid expression.
Description
In general, you can use a subtype conversion function to write code to show that the results of some operations should be represented as a specific data type, not the default type. For example, in the case of currency, single-precision, or double-precision operations, you use CInt or CLng to force an integer operation.
The CInt function is used for internationally recognized format conversions from other data types to Integer subtypes. For example, the recognition of decimal separators, such as thousands, may depend on the locale of the system.
If the expression is outside the acceptable range of the Integer subtype, an error occurs.
The following example uses the CInt function to convert a value to an Integer:
Dim MyDouble, MyIntMyDouble = 2345.5678 Is Double . CInt(MyDouble) ' MyInt contains 2346 .
Note that CInt differs from the Fix and Int functions by removing numeric decimal parts, but by rounding. When the decimal part is exactly equal to 0.5, CInt always rounded it to the nearest even number. For example, 0.5 is rounded to 0, and 1.5 is rounded to 2.