Function Reference


Number

Returns the numeric representation of an expression.

Number ( expression [, flag = 0] )

Parameters

expression An expression to convert into a number.
flag [optional] Defines behavior.
Can be one of the following:
    $NUMBER_AUTO (0) = (default) the result is auto-sized integer. See remarks.
    $NUMBER_32BIT (1) = the result is 32bit integer.
    $NUMBER_64BIT (2) = the result is 64bit integer.
    $NUMBER_DOUBLE (3) = the result is double.

Constants are defined in "AutoItConstants.au3".

Return Value

Returns a number.

Remarks

If you pass number, function outputs the input.
A string beginning with letters has a numeric value of zero. A string beginning with digits has non-numeric characters stripped at the from the first one. Valid characters for Double numbers does not start the stripping.
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 are signed.

Related

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

Example

#include <MsgBoxConstants.au3>

Local $bNumber1 = Number(1 + 2 + 10) ; Returns 13.
Local $bNumber2 = Number("3.14") ; Returns 3.14.
Local $bNumber3 = Number("24/7") ; Returns 24.
Local $bNumber4 = Number("tmp3") ; Returns 0 as this is a string.
Local $bNumber5 = Number("1,000,000") ; Returns 1 as it strips everything after and including the first comma.

MsgBox($MB_SYSTEMMODAL, "", "The following values were converted to a numeric value:" & @CRLF & _
        $bNumber1 & @CRLF & $bNumber2 & @CRLF & $bNumber3 & @CRLF & $bNumber4 & @CRLF & $bNumber5)