VBS tutorial: Functions – CLng functions

Time:2021-9-12

CLng function

Returns an expression that has been converted toLongSubtypeVariant

CLng(expression)

expressionArgument is any valid expression.

explain

In general, you can write code using subtype data conversion functions 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 operation, single precision or double precision arithmetic operation, useCIntorCLngFunction to force an integer operation.

CLngThe function is used to transfer data from other data types toLongSubtypes are converted to internationally recognized formats. For example, the identification of decimal and thousand separators depends on the locale of the system.

IfexpressionIf the value is not within the allowable range of long subtype, an error will occur.

The following example usesCLngThe function converts the value to long:

Dim MyVal1, MyVal2, MyLong1, MyLong2MyVal1 = 25427.45: MyVal2 = 25427.55        '  Myval1, myval2 are double precision values. MyLong1 = CLng(MyVal1)           '  MyLong1 25427。 MyLong2 = CLng(MyVal2)            '  Mylong2 contains 25428.

be careful    CLngdifferFixandIntThe function removes the decimal part, but rounds it. When the decimal part is exactly equal to 0.5,CLngThe function always rounds it to the nearest even number. For example, 0.5 is rounded to 0 and 1.5 is rounded to 2.