JavaScript (ES2026) reference · 12 entries
JavaScript Number Methods and Properties
Number methods and constants: isInteger(), isNaN(), parseInt(), toFixed(), toLocaleString(), MAX_SAFE_INTEGER and EPSILON, with examples you can run.
Static methods (Number.isInteger()) test or parse values; instance methods (price.toFixed(2)) format a
number as a string. All numbers are 64-bit floats, which is why 0.1 + 0.2 isn't exactly 0.3.
| Name | Description | Since |
|---|---|---|
Number.isInteger() |
Return true if a value is a number with no fractional part. Strings aren't converted, so Number.isInteger("5") is false. | ES2015 |
Number.isSafeInteger() |
Return true if a value is an integer that can be represented exactly, between -(2^53 - 1) and 2^53 - 1. | ES2015 |
Number.isFinite() |
Return true if a value is a finite number. Unlike the global isFinite(), it doesn't convert strings. | ES2015 |
Number.isNaN() |
Return true only if a value is the number NaN. Unlike the global isNaN(), it doesn't convert strings first. | ES2015 |
Number.parseFloat() |
Parse a decimal number from the start of a string, ignoring trailing text. Same as the global parseFloat(). | ES2015 |
Number.parseInt() |
Parse an integer from the start of a string in a given base (radix). Always pass the radix, usually 10. | ES2015 |
Number.MAX_SAFE_INTEGER |
The largest integer JavaScript numbers can represent exactly: 2^53 - 1, or 9,007,199,254,740,991. | ES2015 |
Number.EPSILON |
The smallest difference between 1 and the next representable number, used as a tolerance when comparing floats. | ES2015 |
number.toFixed() |
Format a number with a fixed number of decimal places, returned as a string. Rounds, but floating-point quirks apply. | ES3 |
number.toPrecision() |
Format a number to a given number of significant digits, using exponential notation when needed. | ES3 |
number.toString() |
Convert a number to a string, optionally in another base such as 2 (binary) or 16 (hexadecimal). | ES1 |
number.toLocaleString() |
Format a number for display using locale rules: thousands separators, decimals, currency and percentages. | ES3 |