共用方式為


CLng Function

Returns an expression that has been converted to a Variant of subtype Long.

                      CLng(expression)

Remarks

The expression argument is any valid expression.

Use the CLng function to provide conversions from any data type to a Long subtype. For example, CLng forces integer arithmetic when currency, single-precision, or double-precision arithmetic would normally occur.

The CLng function uses the locale setting of your system to determine how to perform conversions. Different decimal separators are properly recognized depending on the locale setting, as are different thousand separators.

If expression lies outside the acceptable range for the Long subtype, an error occurs.

The following example uses the CLng function to convert a value 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.

Note

When the fractional part of a value is exactly 0.5, the CLng function rounds to the closest even number. For example, 0.5 rounds to 0, 1.5 rounds to 2, and 3.5 rounds to 4. The purpose of rounding to the closest even number is to compensate for a bias that could accumulate when many numbers are added together.

CLng differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number.

Requirements

Version 1

See Also

Reference

CBool Function

CByte Function

CCur Function

CDate Function

CDbl Function

CInt Function

CSng Function

CStr Function

Int, Fix Functions

Round Function

Change History

Date

History

Reason

August 2009

Modified remarks and note.

Customer feedback.