Number : Object
Converts the specified BigInt to a Number. For value
s outside the range MIN_SAFE_INTEGER to MAX_SAFE_INTEGER, the returned Number may be an approximation of value
.
Example:
RunResults:
Coerces value
to a number. Usually this method is not necessary since JavaScript will automatically coerce a value to a number when it is used in a number context. +value
is another way to coerce a value to a number. This coercion is very strict and will return NaN
if the specified value cannot be converted to a Number
. parseInt
and paseFloat
can also be used to convert a String
to a Number
.
Example:
RunResults:
Instance Methods
Returns a string representation of this
in scientific notation. If fractionalDigits
is specified, that many digits will follow the '.'.
Example:
RunResults:
Returns a string representation of this
that conforms to the number format specification of the current locale.
Example:
RunResults:
Number Properties
EPSILON
is the difference between 1
and the next Number greater than 1 that is representable in JavaScript.
Example:
RunResults:
The largest possible integer such that MAX_SAFE_INTEGER
and MAX_SAFE_INTEGER + 1
can both be represented exactly in JavaScript. See also MIN_SAFE_INTEGER
and Number.isSafeInteger()
.
Example:
RunResults:
The largest possible Number less than infinity that can be represented in JavaScript.
Example:
RunResults:
The smallest possible integer such that MIN_SAFE_INTEGER
and MIN_SAFE_INTEGER - 1
can both be represented exactly in JavaScript. See also MAX_SAFE_INTEGER
and Number.isSafeInteger()
.
Example:
RunResults:
The smallest possible Number greater than 0 that can be represented in JavaScript.
Example:
RunResults:
Floating point Not a Number. Signifies an error in a calculation. NaN
is never equal to another Number
, even if it is NaN
. To check if something is NaN
, use isNan() or Number.isNan(). Also exists as NaN
in the global namespace.
Example:
RunResults:
Number Methods
Returns true
if x
is not NaN
, +Infinity
, or -Infinity
. See also the global isFinite(x)
method.
Example:
RunResults:
Returns true
if x
is NaN
. NaN
is never equal to another Number
, even if it is NaN
, so you must use isNaN
to check for NaN
. See also the global isNaN(x)
method and Object.is().
Example:
RunResults:
Returns true
if x
is greater than or equal to MIN_SAFE_INTEGER
and less than or equal to MAX_SAFE_INTEGER
. Adding or subtracting 1
to numbers outside this range may not produce a change in the value due to lack of floating point precision.
Example:
RunResults:
Converts str
into a floating point number. parseFloat
is less scrict than using Number(str)
(or +str
) to convert to a Number because it ignores extra characters after the numeric portion of the string. If the first character is not a valid number, parseFloat
will return NaN
. Also exists as parseFloat
in the global namespace.
Example:
RunResults:
Converts str
into an integral number. If base
is not specified, parseInt
will attempt to determine the base to use depending on the input ('0x'
prefix is base 16). parseInt
is less scrict than using Number(str)
(or +str
) to convert to a Number because it ignores extra characters after the numeric portion of the string. If the first character is not a valid number in the specified base
, parseInt
will return NaN
. Also exists as parseInt
in the global namespace.