JavaScript Number Object
Number is JavaScript's type for numbers, both whole and decimal, stored as 64-bit floating point. The Number object provides constants such as MAX_SAFE_INTEGER and methods for checking and formatting numbers.
Description
The Number type represents both integers and decimals using 64-bit floating point (IEEE 754). That gives about 15 to 17 significant digits, which is why 0.1 + 0.2 isn't exactly 0.3, and integers are only exact up to Number.MAX_SAFE_INTEGER (253 - 1). Special values include Infinity, -Infinity and NaN ("not a number").
Calling Number(value) converts a value to a number, returning NaN if it can't. Static methods such as Number.isInteger() and Number.isNaN() check numbers without type conversion, and instance methods such as toFixed() and toLocaleString() format them. For integers larger than the safe range, use BigInt.
JavaScript numbers can be written in decimal, hexadecimal (0xff), octal (0o17), binary (0b1010) and exponential (1e6) notation, and underscores can separate digits for readability, as in 1_000_000. To parse numbers from text, Number() requires the whole string to be numeric, while parseInt() and parseFloat() read as far as they can. For money, consider storing whole units such as cents to avoid rounding issues.
Creating
123
1.5e3
Number(value)Static properties
| Name | Description |
|---|---|
Number.EPSILON | Number.EPSILON is the smallest gap between 1 and the next representable number. |
Number.MAX_SAFE_INTEGER | Number.MAX_SAFE_INTEGER is the largest integer JavaScript numbers can store exactly: 9007199254740991. |
Number.MAX_VALUE | Number.MAX_VALUE is the largest number JavaScript can represent. |
Static methods
| Name | Description |
|---|---|
Number.isFinite() | The Number.isFinite() static method checks whether a value is a finite number, without converting other types to numbers first. |
Number.isInteger() | The Number.isInteger() static method checks whether a value is a whole number. |
Number.isNaN() | The Number.isNaN() static method checks whether a value is NaN, without the confusing type conversion of the global isNaN(). |
Number.isSafeInteger() | The Number.isSafeInteger() static method checks whether a value is an integer small enough to be stored exactly. |
Number.parseFloat() | The Number.parseFloat() static method reads a decimal number from the start of a string. |
Number.parseInt() | The Number.parseInt() static method reads an integer from the start of a string, in a given base. |
Instance methods
| Name | Description |
|---|---|
Number.prototype.toFixed() | The toFixed() method formats a number with a fixed number of decimal places and returns it as a string. |
Number.prototype.toLocaleString() | The toLocaleString() method formats a number for a given language and region, with the right digit grouping, decimal separator and optional currency. |
Number.prototype.toPrecision() | The toPrecision() method formats a number to a given number of significant digits and returns it as a string. |
Number.prototype.toString() | The toString() method converts a number to a string, optionally in another base such as binary (2) or hexadecimal (16). |
Example
Browser Support
The following information will show you the current browser support for the Number object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





