# 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` )

When `Number`

is called with argument `value`, the following steps are taken:

- If
`value`is present, then - 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]]:

# 21.1.2.2 Number.isFinite ( `number` )

When `Number.isFinite`

is called with one argument `number`, the following steps are taken:

- If
Type (`number`) is not Number, returnfalse . - If
`number`isNaN ,+∞ _{𝔽}, or-∞ _{𝔽}, returnfalse . - Otherwise, return
true .

# 21.1.2.3 Number.isInteger ( `number` )

When `Number.isInteger`

is called with one argument `number`, the following steps are taken:

- Return !
IsIntegralNumber (`number`).

# 21.1.2.4 Number.isNaN ( `number` )

When `Number.isNaN`

is called with one argument `number`, the following steps are taken:

- If
Type (`number`) is not Number, returnfalse . - If
`number`isNaN , returntrue . - Otherwise, return
false .

This function differs from the global isNaN function (

# 21.1.2.5 Number.isSafeInteger ( `number` )

When `Number.isSafeInteger`

is called with one argument `number`, the following steps are taken:

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

# 21.1.2.6 Number.MAX_SAFE_INTEGER

The value of `Number.MAX_SAFE_INTEGER`

is the largest

The value of `Number.MAX_SAFE_INTEGER`

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

This property has the attributes { [[Writable]]:

# 21.1.2.7 Number.MAX_VALUE

The value of `Number.MAX_VALUE`

is the largest positive finite value of the Number type, which is approximately ^{308}

This property has the attributes { [[Writable]]:

# 21.1.2.8 Number.MIN_SAFE_INTEGER

The value of `Number.MIN_SAFE_INTEGER`

is the smallest

The value of `Number.MIN_SAFE_INTEGER`

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

# 21.1.2.9 Number.MIN_VALUE

The value of `Number.MIN_VALUE`

is the smallest positive value of the Number type, which is approximately ^{-324}

In the `Number.MIN_VALUE`

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

# 21.1.2.10 Number.NaN

The value of `Number.NaN`

is

# 21.1.2.11 Number.NEGATIVE_INFINITY

The value of `Number.NEGATIVE_INFINITY`

is _{𝔽}.

# 21.1.2.12 Number.parseFloat ( `string` )

The value of the `Number.parseFloat`

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

The value of the `Number.parseInt`

# 21.1.2.14 Number.POSITIVE_INFINITY

The value of `Number.POSITIVE_INFINITY`

is _{𝔽}.

# 21.1.2.15 Number.prototype

The initial value of `Number.prototype`

is the

# 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

The abstract operation thisNumberValue takes argument `value`. It performs the following steps when called:

The phrase “this

# 21.1.3.1 Number.prototype.constructor

The initial value of `Number.prototype.constructor`

is

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

Return a String containing this `fractionDigits` digits after the significand's decimal point. If `fractionDigits` is

- Let
`x`be ?thisNumberValue (this value). - Let
`f`be ?ToIntegerOrInfinity (`fractionDigits`). Assert : If`fractionDigits`isundefined , then`f`is 0.- If
`x`is not finite, return !Number::toString (`x`). - 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`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. Note that the decimal representation of`n`has`f`+ 1 digits,`n`is not divisible by 10, and the least significant digit of`n`is not necessarily uniquely determined by these criteria.

- 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, let`c`be"+" . - 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` )

`toFixed`

returns a String containing this `fractionDigits` digits after the decimal point. If `fractionDigits` is

The following steps are performed:

- Let
`x`be ?thisNumberValue (this value). - Let
`f`be ?ToIntegerOrInfinity (`fractionDigits`). Assert : If`fractionDigits`isundefined , then`f`is 0.- If
`f`is not finite, throw aRangeError exception. - If
`f`< 0 or`f`> 100, throw aRangeError exception. - If
`x`is not finite, return !Number::toString (`x`). - 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 the String"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 the `Number.prototype.toLocaleString`

method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the `toLocaleString`

method is used.

Produces a String value that represents this `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` )

Return a String containing this `precision` - 1`precision` significant digits. If `precision` is

- Let
`x`be ?thisNumberValue (this value). - If
`precision`isundefined , return !ToString (`x`). - Let
`p`be ?ToIntegerOrInfinity (`precision`). - If
`x`is not finite, return !Number::toString (`x`). - 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`.

The following steps are performed:

- Let
`x`be ?thisNumberValue (this value). - If
`radix`isundefined , let`radixMV`be 10. - Else, let
`radixMV`be ?ToIntegerOrInfinity (`radix`). - If
`radixMV`< 2 or`radixMV`> 36, throw aRangeError exception. - If
`radixMV`= 10, return !ToString (`x`). - Return the String representation of this
Number value using the radix specified by`radixMV`. Letters`a`

-`z`

are used for digits with values 10 through 35. The precise algorithm isimplementation-defined , however the algorithm should be a generalization of that specified in6.1.6.1.20 .

The `toString`

function is not generic; it throws a

The `toString`

method is _{𝔽}.

# 21.1.3.7 Number.prototype.valueOf ( )

- Return ?
thisNumberValue (this value).

# 21.1.4 Properties of Number Instances

Number instances are