# 21.1 Number Objects

# 21.1.1 The Number Constructor

The Number

- is %Number%.
- is the initial value of the
"Number" property of theglobal object . - creates and initializes a new Number object when called as a
constructor . - performs a type conversion when called as a function rather than as a
constructor . - may be used as the value of an
`extends`

clause of a class definition. Subclassconstructors that intend to inherit the specified Number behaviour must include a`super`

call to the Numberconstructor to create and initialize the subclass instance with a`[[NumberData]]`internal slot.

# 21.1.1.1 Number ( `value` )

This function performs the following steps when called:

- If
`value`is present, then- Let
`prim`be ?ToNumeric (`value`). - If
`prim`is a BigInt , let`n`be𝔽 (ℝ (`prim`)). - Otherwise, let
`n`be`prim`.

- Let
- Else,
- Let
`n`be+0 _{𝔽}.

- Let
- If NewTarget is
undefined , return`n`. - Let
`O`be ?OrdinaryCreateFromConstructor (NewTarget,"%Number.prototype%" , «`[[NumberData]]`»). - Set
`O`.`[[NumberData]]`to`n`. - Return
`O`.

# 21.1.2 Properties of the Number Constructor

The Number

- has a
`[[Prototype]]`internal slot whose value is%Function.prototype% . - has the following properties:

# 21.1.2.1 Number.EPSILON

The value of `Number.EPSILON`

is the ^{-16}.

This property has the attributes { `[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.2 Number.isFinite ( `number` )

This function performs the following steps when called:

- If
`number`is not a Number , returnfalse . - If
`number`is notfinite , returnfalse . - Otherwise, return
true .

# 21.1.2.3 Number.isInteger ( `number` )

This function performs the following steps when called:

- Return
IsIntegralNumber (`number`).

# 21.1.2.4 Number.isNaN ( `number` )

This function performs the following steps when called:

- If
`number`is not a Number , returnfalse . - If
`number`isNaN , returntrue . - Otherwise, return
false .

This function differs from the global isNaN function (

# 21.1.2.5 Number.isSafeInteger ( `number` )

An `n` is a "safe integer" if and only if the `n` is not the

This function performs the following steps when called:

- If
IsIntegralNumber (`number`) istrue , then - Return
false .

# 21.1.2.6 Number.MAX_SAFE_INTEGER

Due to rounding behaviour necessitated by precision limitations of `Number.MAX_SAFE_INTEGER`

is shared with at least one other `9007199254740992`

and `9007199254740993`

evaluate to the Number value _{𝔽}.

The value of `Number.MAX_SAFE_INTEGER`

is _{𝔽} (^{53} - 1)).

This property has the attributes { `[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.7 Number.MAX_VALUE

The value of `Number.MAX_VALUE`

is the largest positive ^{308}

This property has the attributes { `[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.8 Number.MIN_SAFE_INTEGER

Due to rounding behaviour necessitated by precision limitations of `Number.MIN_SAFE_INTEGER`

is shared with at least one other `-9007199254740992`

and `-9007199254740993`

evaluate to the Number value _{𝔽}.

The value of `Number.MIN_SAFE_INTEGER`

is _{𝔽} (^{53} - 1))).

`[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.9 Number.MIN_VALUE

The value of `Number.MIN_VALUE`

is the smallest positive value of the ^{-324}

In the `Number.MIN_VALUE`

must be the smallest non-zero positive value that can actually be represented by the implementation.

`[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.10 Number.NaN

The value of `Number.NaN`

is

`[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.11 Number.NEGATIVE_INFINITY

The value of `Number.NEGATIVE_INFINITY`

is _{𝔽}.

`[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.12 Number.parseFloat ( `string` )

The initial value of the

# 21.1.2.13 Number.parseInt ( `string`, `radix` )

The initial value of the

# 21.1.2.14 Number.POSITIVE_INFINITY

The value of `Number.POSITIVE_INFINITY`

is _{𝔽}.

`[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.2.15 Number.prototype

The initial value of `Number.prototype`

is the

`[[Writable]]`: `[[Enumerable]]`: `[[Configurable]]`:

# 21.1.3 Properties of the Number Prototype Object

The Number prototype object:

- is %Number.prototype%.
- is an
ordinary object . - is itself a Number object; it has a
`[[NumberData]]`internal slot with the value+0 _{𝔽}. - has a
`[[Prototype]]`internal slot whose value is%Object.prototype% .

Unless explicitly stated otherwise, the methods of the Number prototype object defined below are not generic and the `[[NumberData]]` internal slot that has been initialized to a Number value.

The phrase “this Number value” within the specification of a method refers to the result returned by calling the abstract operation

# 21.1.3.1 Number.prototype.constructor

The initial value of `Number.prototype.constructor`

is

# 21.1.3.2 Number.prototype.toExponential ( `fractionDigits` )

This method returns a String containing this Number value represented in decimal exponential notation with one digit before the significand's decimal point and `fractionDigits` digits after the significand's decimal point. If `fractionDigits` is

It performs the following steps when called:

- Let
`x`be ?ThisNumberValue (this value). - Let
`f`be ?ToIntegerOrInfinity (`fractionDigits`). Assert : If`fractionDigits`isundefined , then`f`is 0.- If
`x`is notfinite , returnNumber::toString (`x`, 10). - If
`f`< 0 or`f`> 100, throw aRangeError exception. - Set
`x`toℝ (`x`). - Let
`s`be the empty String. - If
`x`< 0, then- Set
`s`to"-" . - Set
`x`to -`x`.

- Set
- If
`x`= 0, then- Let
`m`be the String value consisting of`f`+ 1 occurrences of the code unit 0x0030 (DIGIT ZERO). - Let
`e`be 0.

- Let
- Else,
- If
`fractionDigits`is notundefined , then- Let
`e`and`n`beintegers such that 10^{f}≤`n`< 10^{f + 1}and for which`n`× 10^{e - f}-`x`is as close to zero as possible. If there are two such sets of`e`and`n`, pick the`e`and`n`for which`n`× 10^{e - f}is larger.

- Let
- Else,
- Let
`e`,`n`, and`ff`beintegers such that`ff`≥ 0, 10^{ff}≤`n`< 10^{ff + 1},𝔽 (`n`× 10^{e - ff}) is𝔽 (`x`), and`ff`is as small as possible. Note that the decimal representation of`n`has`ff`+ 1 digits,`n`is not divisible by 10, and the least significant digit of`n`is not necessarily uniquely determined by these criteria. - Set
`f`to`ff`.

- Let
- Let
`m`be the String value consisting of the digits of the decimal representation of`n`(in order, with no leading zeroes).

- If
- If
`f`≠ 0, then- Let
`a`be the first code unit of`m`. - Let
`b`be the other`f`code units of`m`. - Set
`m`to thestring-concatenation of`a`,"." , and`b`.

- Let
- If
`e`= 0, then- Let
`c`be"+" . - Let
`d`be"0" .

- Let
- Else,
- If
`e`> 0, then- Let
`c`be"+" .

- Let
- Else,
Assert :`e`< 0.- Let
`c`be"-" . - Set
`e`to -`e`.

- Let
`d`be the String value consisting of the digits of the decimal representation of`e`(in order, with no leading zeroes).

- If
- Set
`m`to thestring-concatenation of`m`,"e" ,`c`, and`d`. - Return the
string-concatenation of`s`and`m`.

For implementations that provide more accurate conversions than required by the rules above, it is recommended that the following alternative version of step

- Let
`e`,`n`, and`f`beintegers such that`f`≥ 0, 10^{f}≤`n`< 10^{f + 1},𝔽 (`n`× 10^{e - f}) is𝔽 (`x`), and`f`is as small as possible. If there are multiple possibilities for`n`, choose the value of`n`for which𝔽 (`n`× 10^{e - f}) is closest in value to𝔽 (`x`). If there are two such possible values of`n`, choose the one that is even.

# 21.1.3.3 Number.prototype.toFixed ( `fractionDigits` )

This method returns a String containing this Number value represented in decimal fixed-point notation with `fractionDigits` digits after the decimal point. If `fractionDigits` is

It performs the following steps when called:

- Let
`x`be ?ThisNumberValue (this value). - Let
`f`be ?ToIntegerOrInfinity (`fractionDigits`). Assert : If`fractionDigits`isundefined , then`f`is 0.- If
`f`is notfinite , throw aRangeError exception. - If
`f`< 0 or`f`> 100, throw aRangeError exception. - If
`x`is notfinite , returnNumber::toString (`x`, 10). - Set
`x`toℝ (`x`). - Let
`s`be the empty String. - If
`x`< 0, then- Set
`s`to"-" . - Set
`x`to -`x`.

- Set
- If
`x`≥ 10^{21}, then - Else,
- Let
`n`be aninteger for which`n`/ 10^{f}-`x`is as close to zero as possible. If there are two such`n`, pick the larger`n`. - If
`n`= 0, let`m`be"0" . Otherwise, let`m`be the String value consisting of the digits of the decimal representation of`n`(in order, with no leading zeroes). - If
`f`≠ 0, then- Let
`k`be the length of`m`. - If
`k`≤`f`, then- Let
`z`be the String value consisting of`f`+ 1 -`k`occurrences of the code unit 0x0030 (DIGIT ZERO). - Set
`m`to thestring-concatenation of`z`and`m`. - Set
`k`to`f`+ 1.

- Let
- Let
`a`be the first`k`-`f`code units of`m`. - Let
`b`be the other`f`code units of`m`. - Set
`m`to thestring-concatenation of`a`,"." , and`b`.

- Let

- Let
- Return the
string-concatenation of`s`and`m`.

The output of `toFixed`

may be more precise than `toString`

for some values because toString only prints enough significant digits to distinguish the number from adjacent Number values. For example,

`(1000000000000000128).toString()`

returns

`(1000000000000000128).toFixed(0)`

returns

# 21.1.3.4 Number.prototype.toLocaleString ( [ `reserved1` [ , `reserved2` ] ] )

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:

This method produces a String value that represents this Number value formatted according to the conventions of the `toString`

.

The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.

# 21.1.3.5 Number.prototype.toPrecision ( `precision` )

This method returns a String containing this Number value represented either in decimal exponential notation with one digit before the significand's decimal point and `precision` - 1`precision` significant digits. If `precision` is

It performs the following steps when called:

- Let
`x`be ?ThisNumberValue (this value). - If
`precision`isundefined , return !ToString (`x`). - Let
`p`be ?ToIntegerOrInfinity (`precision`). - If
`x`is notfinite , returnNumber::toString (`x`, 10). - If
`p`< 1 or`p`> 100, throw aRangeError exception. - Set
`x`toℝ (`x`). - Let
`s`be the empty String. - If
`x`< 0, then- Set
`s`to the code unit 0x002D (HYPHEN-MINUS). - Set
`x`to -`x`.

- Set
- If
`x`= 0, then- Let
`m`be the String value consisting of`p`occurrences of the code unit 0x0030 (DIGIT ZERO). - Let
`e`be 0.

- Let
- Else,
- Let
`e`and`n`beintegers such that 10^{p - 1}≤`n`< 10^{p}and for which`n`× 10^{e - p + 1}-`x`is as close to zero as possible. If there are two such sets of`e`and`n`, pick the`e`and`n`for which`n`× 10^{e - p + 1}is larger. - Let
`m`be the String value consisting of the digits of the decimal representation of`n`(in order, with no leading zeroes). - If
`e`< -6 or`e`≥`p`, thenAssert :`e`≠ 0.- If
`p`≠ 1, then- Let
`a`be the first code unit of`m`. - Let
`b`be the other`p`- 1 code units of`m`. - Set
`m`to thestring-concatenation of`a`,"." , and`b`.

- Let
- If
`e`> 0, then- Let
`c`be the code unit 0x002B (PLUS SIGN).

- Let
- Else,
Assert :`e`< 0.- Let
`c`be the code unit 0x002D (HYPHEN-MINUS). - Set
`e`to -`e`.

- Let
`d`be the String value consisting of the digits of the decimal representation of`e`(in order, with no leading zeroes). - Return the
string-concatenation of`s`,`m`, the code unit 0x0065 (LATIN SMALL LETTER E),`c`, and`d`.

- Let
- If
`e`=`p`- 1, return thestring-concatenation of`s`and`m`. - If
`e`≥ 0, then- Set
`m`to thestring-concatenation of the first`e`+ 1 code units of`m`, the code unit 0x002E (FULL STOP), and the remaining`p`- (`e`+ 1) code units of`m`.

- Set
- Else,
- Set
`m`to thestring-concatenation of the code unit 0x0030 (DIGIT ZERO), the code unit 0x002E (FULL STOP), -(`e`+ 1) occurrences of the code unit 0x0030 (DIGIT ZERO), and the String`m`.

- Set
- Return the
string-concatenation of`s`and`m`.

# 21.1.3.6 Number.prototype.toString ( [ `radix` ] )

The optional `radix` should be an _{𝔽} to _{𝔽}. If `radix` is _{𝔽} is used as the value of `radix`.

This method performs the following steps when called:

- Let
`x`be ?ThisNumberValue (this value). - If
`radix`isundefined , let`radixMV`be 10. - Else, let
`radixMV`be ?ToIntegerOrInfinity (`radix`). - If
`radixMV`is not in theinclusive interval from 2 to 36, throw aRangeError exception. - Return
Number::toString (`x`,`radixMV`).

This method is not generic; it throws a

The _{𝔽}.

# 21.1.3.7 Number.prototype.valueOf ( )

- Return ?
ThisNumberValue (this value).

# 21.1.3.7.1 ThisNumberValue ( `value` )

The abstract operation ThisNumberValue takes argument `value` (an

- If
`value`is a Number , return`value`. - If
`value`is an Object and`value`has a`[[NumberData]]`internal slot, then- Let
`n`be`value`.`[[NumberData]]`. Assert :`n`is a Number .- Return
`n`.

- Let
- Throw a
TypeError exception.

# 21.1.4 Properties of Number Instances

Number instances are `[[NumberData]]` internal slot. The `[[NumberData]]` internal slot is the Number value represented by this Number object.