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

MAX_VALUE : Number

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

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(). 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: