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. If expression is outside the range of an Integer, a run-time error occurs.

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.

Use CInt instead of Val to provide internationally aware conversions from a string to a numeric type.

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

License: CC-BY-4.0 Code license: MIT Attribution: VBA-Docs