Returns the numeric representation of an expression.
Number ( expression [, flag = 0] )
|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".
Note: A number is consider a value that is either an integer, floating-point value, scientific or hexadecimal notation.
If the string contains a number, the result will be a number.
If the string contains an expression (AutoIt or variable type) with a number at the beginning of the expression, then this value will be returned as a number, will all other value being ignored.
If the string begins with a number but continues with additional non-number characters, the number part is returned as a number only.
If the expression parameter is an arithmetic expression, then expression will be evaluated first before returning the result as a number.
If hexadecimal notation, but values passed 0x are non-hexadecimal (0-9, A-F), then 0 is returned.
If unary plus/minus is used e.g. +30 or -30, then this will be returned as their positive and negative counterparts.
If all other cases 0 is returned.
In the above cases, the function returns an integer if the mantissa of the result is zero or flag is $NUMBER_32BIT or $NUMBER_64BIT. These flags will truncate a floating-point result.
The default for an integer result is to store it in 32 bits if possible. If not, it is stored in 64 bits.If not is stored in a floaring-point.
Binary, Ceiling, Floor, HWnd, Int, Ptr, Round, String
#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $dNumber1 = Number(1 + 2 + 10) ; Returns 13. Local $dNumber2 = Number("3.14") ; Returns 3.14. Local $dNumber3 = Number("24/7") ; Returns 24. Local $dNumber4 = Number("tmp3") ; Returns 0 as this is a string. Local $dNumber5 = Number("1,000,000") ; Returns 1 as it strips everything after (and including) the first comma. Local $dNumber6 = Number("24autoit") ; Returns 24 Local $dNumber7 = Number("1.2e3sa") ; Returns 1200 Local $dNumber8 = Number("0xcade") ; Returns 51934 Local $dNumber9 = Number(Ptr(5)) ; Returns 5 Local $dNumber10 = Number(Binary("abc")) ; Returns decimal value of 0x616263 = 6513249 Local $dNumber11 = Number(ObjCreate("Scripting.Dictionary")) ; Returns 0 Local $dNumber12 = Number(1 > 3 Or 5 <= 15) ; Returns 1 Local $dNumber13 = Number("-30") ; Returns 30 MsgBox($MB_SYSTEMMODAL, "", "The following values were converted to a numeric value:" & @CRLF & _ "$dNumber1 = " & $dNumber1 & @CRLF & _ "$dNumber2 = " & $dNumber2 & @CRLF & _ "$dNumber3 = " & $dNumber3 & @CRLF & _ "$dNumber4 = " & $dNumber4 & @CRLF & _ "$dNumber5 = " & $dNumber5 & @CRLF & _ "$dNumber6 = " & $dNumber6 & @CRLF & _ "$dNumber7 = " & $dNumber7 & @CRLF & _ "$dNumber8 = " & $dNumber8 & @CRLF & _ "$dNumber9 = " & $dNumber9 & @CRLF & _ "$dNumber10 = " & $dNumber10 & @CRLF & _ "$dNumber11 = " & $dNumber11 & @CRLF & _ "$dNumber12 = " & $dNumber12 & @CRLF & _ "$dNumber13 = " & $dNumber13 & @CRLF)