CLng function
Returns an expression that has been converted to a Variantof a Long subtype.
CLng(expression)
The expression parameter is any valid expression.
Description
Typically, you can use subtype data conversion functions to write code to show that the results of certain operations should be expressed as a specific data type, not as a default data type. For example, in the case of currency operations, single-precision, or double-precision arithmetic operations, the CInt or CLng functions are used to force integer operations.
The CLng function is used for internationally recognized format conversions from other data types to Long subtypes. For example, the recognition of the decimal separator and the thousand separator depends on the locale of the system.
If the expression value is not within the allowable range of a long subtype, an error occurs.
The following example uses the CLng function to convert a value to Long:
is a double value. CLng(MyVal1)
' MyLong1 25427
. CLng(MyVal2)
contains
.
Note that CLng differs from the Fix and Int functions in removing decimal parts, but by rounding. When the decimal part is exactly equal to 0.5, the CLng function always rounds it to the even number closest to it. For example, 0.5 rounded to 0, and 1.5 rounded to 2.