MS Access: CInt Function
This MSAccess tutorial explains how to use the Access CInt function with syntax and examples.
Description
The Microsoft Access CINT function converts a value to an integer.
Syntax
The syntax for the CInt function in MS Access is:
CInt( expression )
Parameters or Arguments
- expression
- The value to convert to an integer.
Returns
The CInt function returns an integer value.
Applies To
The CInt function can be used in the following versions of Microsoft Access:
- Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000
Example in VBA Code
The CInt function can be used in VBA code in Microsoft Access.
For example:
Dim LValue As Integer LValue = CInt(8.45)
In this example, the variable called LValue would now contain the value of 8.
Be careful using CInt. If you were to use the following code:
Dim LValue As Integer LValue = CInt(8.5)
The variable LValue would still contain the value of 8. Until the fraction is greater than .5, the CInt function will not round the number up.
If the fraction is less than or equal to .5, the result will round down.
If the fraction is greater than .5, the result will round up.
We've found it useful in the past to add 0.0001 to the value before applying the CInt function to simulate the regular rounding process.
For example, CInt(8.50001) will result in a value of 9.
Advertisements