函数参考


Number

返回某表达式的数值结果.

Number ( 表达式 [, 标志 ] )

参数

表达式 要转换成数字的一个表达式.
标志 [可选参数] Defines behavior.
Can be one of the following:
  Default = the result is auto-sized integer. See remarks.
  1 = the result is 32bit integer.
  2 = the result is 64bit integer.
  3 = the result is double.

返回值

返回一个数字.

注意/说明

如果你输入一个数字,函数将原样输出.
以字母开头的字符串将被视为数值零.以数字开头的字符串将返回被(首个)非数字字符截断后的结果.
Default behavior results in auto-sized integer. If input value after conversion is within the range of 32bit integer the result is 32bit integer. If not the result is 64bit integer. Both signed.

相关

Int, String, Binary, Ceiling, Floor, HWnd, Ptr, Round

示例/演示


Local $iNumber1 = Number(1 + 2 + 10) ; Returns 13.
Local $iNumber2 = Number("3.14") ; Returns 3.14.
Local $iNumber3 = Number("24/7") ; Returns 24.
Local $iNumber4 = Number("tmp3") ; Returns 0 as this is a string.
Local $iNumber5 = Number("1,000,000") ; Returns 1 as it strips everything after the first comma.

MsgBox(4096, "", "The following values were converted to a numeric value:" & @CRLF & _
        $iNumber1 & @CRLF & $iNumber2 & @CRLF & $iNumber3 & @CRLF & $iNumber4 & @CRLF & $iNumber5)