CInt 函数

将任意字符串或数字表达式转换为整数。

语法:


CInt (Expression As Variant) As Integer

返回值:

Integer

参数:

Expression: Any string or numeric expression that you want to convert. To convert a string expression, the number must be entered using a dot "." as the decimal point and a comma "," as the thousands separator (for instance 123,456.78), which may differ from your Collabora Office language settings.

If the argument is string, the function trims the leading white space; then it tries to recognize a number in following characters. The syntax below are recognized:

The rest of the string is ignored. If the string is not recognized, e.g. when after trimming leading whitespace it doesn't start with plus, minus, a decimal digit, or "&", or when the sequence after "&O" is longer than 11 characters or contains an alphabetic character, the numeric value of expression is 0.

If the argument is an error, the error number is used as numeric value of the expression.

If the argument is a date, number of days since 1899-12-30 (serial date) is used as numeric value of the expression. Time is represented as fraction of a day.

After calculating the numeric value of the expression, it is rounded to the nearest integer (if needed), and if the result is not between -32768 and 32767, Collabora Office Basic reports an overflow error. Otherwise, the result is returned.

错误代码:

5 无效的过程调用

示例:

Numeric expressions are displayed according to Collabora Office language settings:


Sub ExampleCountryConvert
    MsgBox CDbl(1234.5678) ' 1234.5678
    MsgBox CInt(1234.5678) ' 1235
    MsgBox CLng(1234+5678) ' 6912
    MsgBox CSng(1234.5678) ' 1234.567749023

    MsgBox CDbl(expression := 5678.1234) ' 5678.1234
    MsgBox CInt(expression := 5678.1234) ' 5678
    MsgBox CLng(expression := 5678+1234) ' 6912
    MsgBox CSng(expression := 5678.1234) ' 5678.123535156
End Sub

请支持我们!