Javascript Number Object

In Javascript number type include floating-point and integer values, its wrapper for primitive numeric values.

A Number object is created using the Number() constructor. In Javascript numbers can be divided into two groups:

Integers - The numbers such as 120, -232, and 5.

floating-point - The fractional numbers such as 4.33, -8.422, and .55

In Javascript primitive number can be declared using the literal notation:

Syntax

OR, you can use Number global object directly

Number Properties

Number object has following properties that are part of every object.

PropertyDescription
MAX_VALUE Return largest positive representable number in Javascript.
MIN_VALUE The smallest positive representable number in Javascript.
NEGATIVE_INFINITY Represents negative infinity (returned on overflow)
NaN Represents a "Not-a-Number" value
POSITIVE_INFINITY Represents positive infinity (returned on overflow)
prototype Allows to add addition of properties and function to all objects
constructor Returns a reference to the function that created the Number object

Number Function

The Number object contains only the default function that are part of every object's definition.

MethodDescription
toExponential() Exponential representation of number.
toFixed() Number of digits to appear after the decimal point.
toLocaleString() Return string with language specific representation of this number.
toPrecision() Defines how many total digits (including digits to the left and right of the decimal) to display of a number.
toString() Returns the string representation of the number's value.
valueOf() Returns the number's value.

Javascript Number Example

Above example will produce following result