CLng Function
Return expression, which has been convertedLongChild typeVariant.
CLng(expression)
ExpressionThe parameter is any valid expression.
Description
Generally, you can use the subtype Data Conversion Function to write code to show that the results of some operations should be expressed as specific data types rather than the default data types. For example, in the case of currency operations, single-precision or double-precision arithmetic operationsCIntOrCLngThe function forces integer operations.
CLngFunction is usedLongSub-types of internationally recognized format conversion. For example, the identification of the decimal separator and the thousands separator depends on the system's region settings.
IfExpressionIf the value is not within the permitted range of the Long subtype, an error occurs.
The following example usesCLngThe function converts the value to Long:
Dim MyVal1, MyVal2, MyLong1, MyLong2MyVal1 = 25427.45: MyVal2 = 25427.55
' MyVal1, MyVal2
Is a double precision value.MyLong1 = CLng(MyVal1)
' MyLong1 25427
.MyLong2 = CLng(MyVal2)
' MyLong2
Include 25428
.
Note CLngDifferent fromFixAndIntThe function deletes the decimal part, but returns the rounded value. When the decimal part is equal to 0.5,CLngThe function always rounds the number to an even number closest to the number. For example, 0.5 is rounded to 0, and 1.5 is rounded to 2.