Clnt Function

Returns an expression that has been converted to a Variant of subtype Integer.

Syntax

CInt(expression)

Remarks

The expression argument is any valid expression.

Use the CInt function to provide internationally aware conversions from any other data type to an Integer subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators.

If expression lies outside the acceptable range for the Integer subtype, an error occurs.

The following example uses the CInt function to convert a value to an Integer:

Example 1:

Dim MyDouble, MyInt
MyDouble = 2345.5678    
MyInt = CInt(MyDouble)   
'Output:  2346

Example 2:

Dim MyString
MyString = "12345.67"    
MyInt = CInt(MyString)  
'Output: 12346

Example 3:

MyDouble = 2.6
MyInt = CInt(MyDouble)   
'Output: 3

Example 4:

MyDouble = 2.4
MyInt = CInt(MyDouble)   
'Output: 2

Example 5:

MyDouble = 1.5
MyInt = CInt(MyDouble) ' 1.5 rounds to 2(nearest even integer)
'Output: 2

Example 6:

MyDouble = 0.5
MyInt = CInt(MyDouble) ' 0.5 rounds to 0(nearest even integer)
'Output: 0

Note:

CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2