Partager via


CInt 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 conversions from any other data type to an Integer subtype. For example, CInt forces integer arithmetic when currency, single-precision, or double-precision arithmetic would normally occur.

The CInt function uses the locale setting of your system to determine how to perform conversions. Different decimal separators are properly recognized depending on the locale setting, 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.

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

Note

When the fractional part of a value is exactly 0.5, the CInt function rounds to the closest even number. For example, 0.5 rounds to 0, 1.5 rounds to 2, and 3.5 rounds to 4. The purpose of rounding to the closest even number is to compensate for a bias that could accumulate when many numbers are added together.

CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number.

Requirements

Version 1

Change History

Date

History

Reason

September 2009

Modified remarks.

Customer feedback.

See Also

CBool Function
CByte Function
CCur Function
CDate Function
CDbl Function
CLng Function
CSng Function
CStr Function
Int, Fix Functions
Round Function