HomePrivacy PolicyFeedbackLink to usSite Map

MS Access: CLng Function


Question:  How do I convert a value to a long integer?


Answer:  To convert a value to a long integer, use the "CLng" function. The syntax for the CLng function is:

CLng( expression )

For example,

Dim LValue As Long

LValue = CLng(35150.45)

In this example, the variable called LValue would now contain the value of 35150.

Be careful using CLng. If you were to use the following code:

Dim LValue As Long

LValue = CLng(35150.5)

The variable LValue would still contain the value of 35150. Until the fraction is greater than .5, the CLng 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 CLng function to simulate the regular rounding process.

For example, CInt(35150.50001) will result in a value of 35151.