CLng

Coerces an expression to a Long.

Syntax: CLng( expression )

expression
required Any valid string or numeric expression in the range -2,147,483,648 to 2,147,483,647. Fractions are rounded.

The return type is Long.

When the fractional part is exactly 0.5, CLng always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. CLng differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number.

Dim Half As Double, TwoAndAHalf As Double, MinusHalf As Double
Half = 0.5: TwoAndAHalf = 2.5: MinusHalf = -0.5
Debug.Print CLng(Half)          ' 0
Debug.Print CLng(TwoAndAHalf)   ' 2
Debug.Print CLng(MinusHalf)     ' 0

Common Errors

Error When
6 (&H6), Overflow expression rounds to a number less than -2,147,483,648 or greater than 2,147,483,647
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 CLng function to convert values to a Long.

Dim MyVal1, MyVal2, MyLong1, MyLong2
MyVal1 = 25427.45: MyVal2 = 25427.55     ' MyVal1, MyVal2 are Doubles.
MyLong1 = CLng(MyVal1)                   ' MyLong1 contains 25427.
MyLong2 = CLng(MyVal2)                   ' MyLong2 contains 25428.

See Also