CLNG(expression)

Returns the expression converted to a long data type (Long).


expressionThe expression to evaluate and convert to a long.

REMARKS
* The Long data type is a Value data type.
* The "expression" can be any number between (- 2.1 E+9) and (2.1 E+9).
* If "expression" includes any fractions or decimals these are rounded.
* If "expression" is outside the range of the data type being converted to, an error occurs.
* Any fractional parts less than or equal to 0.5 are rounded to the nearest even number.
* Any fractional parts greater than 0.5 are rounded up.
* You can use the CDBL function to return an expression converted to a double data type.
* You can use the CINT function to return an expression converted to an integer data type.
* You can use the CSNG function to return an expression converted to a single data type.
* You can use the CLNGLNG function to return the expression converted to a LongLong (64 bit platform) data type.
* You can use the CLNGPTR function to return a LongPtr data type.
* For a full list of conversion functions refer to the Explicit Conversion page.
* For the Microsoft documentation refer to docs.microsoft.com

Debug.Print CLng(0.5)        '= 0  
Debug.Print CLng(0.6) '= 1
Debug.Print CLng(1.5) '= 2
Debug.Print CLng(2.5) '= 2
Debug.Print CLng(2.6) '= 3
Debug.Print CLng(2.9) '= 3
Debug.Print CLng(3.5) '= 4
Debug.Print CLng("1234567") '= 1234567

Dim lNumber As Long
Dim dbValue As Double
dbValue = 30.75
lNumber = CLng(dbValue)
Debug.Print lNumber
Debug.Print TypeName(lNumber) '"Long"

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited Top