JavaScripture
Contribute via GitHub Feedback

JavaScript Number : Object

A numerical value. JavaScript stores numbers as 64 bit (8 byte) double precision floats.

Number(value : Object) : Number

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:

Run

Results:

 

Constructors

new Number(value : Number) : Object

Creates a box for value.

Example:

Run

Results:

 

Instance Methods

toExponential([fractionalDigits : Number]) : String

Returns a string representation of this in scientific notation. If fractionalDigits is specified, that many digits will follow the '.'.

Example:

Run

Results:

 

toFixed([fractionalDigits = 0 : Number]) : String

Returns a string representation of this with fractionalDigits following the '.'.

Example:

Run

Results:

 

toLocaleString() : String

Returns a string representation of this that conforms to the number format specification of the current locale.

Example:

Run

Results:

 

toPrecision(precision : Number) : String

Returns a string representation of this with precision significant digits.

Example:

Run

Results:

 

toString([base = 10 : Number]) : String

Returns a string representation of this in the specified base. base must be an integer between 2 and 36.

Example:

Run

Results:

 

Number Properties

EPSILON : Number

EPSILON is the difference between 1 and the next Number greater than 1 that is representable in JavaScript.

Example:

Run

Results:

 

MAX_SAFE_INTEGER : Number

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:

Run

Results:

 

MAX_VALUE : Number

The largest possible Number less than infinity that can be represented in JavaScript.

Example:

Run

Results:

 

MIN_SAFE_INTEGER : Number

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:

Run

Results:

 

MIN_VALUE : Number

The smallest possible Number greater than 0 that can be represented in JavaScript.

Example:

Run

Results:

 

NEGATIVE_INFINITIY : Number

Negative infinity.

Example:

Run

Results:

 

NaN : Number

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:

Run

Results:

 

POSITIVE_INFINITIY : Number

Positive infinity. Also exists as Infinity in the global namespace.

Example:

Run

Results:

 

Number Methods

isFinite(x : Number) : Boolean

Returns true if x is not NaN, +Infinity, or -Infinity. See also the global isFinite(x) method.

Example:

Run

Results:

 

isInteger(x : Number) : Boolean

Returns true if x is an integer.

Example:

Run

Results:

 

isNaN(x : Number) : Boolean

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.

Example:

Run

Results:

 

isSafeInteger(x : Number) : Boolean

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:

Run

Results: