CInt

Coerces an expression to an Integer.

Syntax: CInt( expression )

expression
required Any valid string or numeric expression in the range -32,768 to 32,767. Fractions are rounded.

The return type is Integer.

When the fractional part is exactly 0.5, CInt always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. Also, Fix and Int always return a value of the same type as is passed in.

CInt is the internationally aware alternative to Val for converting a string to a numeric type.

Common Errors

Error When
6 (&H6), Overflow expression rounds to a number less than -32,768 or greater than 32,767
13 (&HD), Type mismatch expression is a string that does not hold a number (a zero-length string included)
94 (&H5E), Invalid use of Null expression is Null

Example

This example uses the CInt function to convert a value to an Integer.

Dim MyDouble, MyInt
MyDouble = 2345.5678                 ' MyDouble is a Double.
MyInt = CInt(MyDouble)               ' MyInt contains 2346.

See Also