Home > Article > Web Front-end > What do javascript numbers represent?
Javascript numbers are represented in 64-bit floating point format. In JavaScript, numbers are not divided into integer types and floating point types. All numbers are floating point types and are uniformly displayed as Number type. They are represented by the 64-bit floating point format defined by the IEEE754 standard; the minimum value that can be represented is "±5e-324".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript numbers are represented in 64-bit floating point format.
JavaScript Unlike many other programming languages, JavaScript does not define different types of numbers, such as integer, short, long, floating point, etc. JavaScript has only one number type.
In JavaScript, numbers are not divided into integer types and floating-point types. All numbers are floating-point types and are uniformly represented by the Number type. JavaScript represents numbers using the 64-bit floating point format defined by the IEEE754 standard. It can represent that the maximum value (Number.MAX_VALUE) is ±1.7976931348623157e 308, and the minimum value (Number.MIN_VALUE) is ±5e-324.
This format uses 64 bits to store values, where 0 to 51 store numbers (fragments), 52 to 62 store exponents, and 63 bits store symbols:
Value (aka Fraction/Mantissa) | Index (Exponent) | Sign (Sign) |
---|---|---|
52 bits (0 - 51) | 11 bits (52 - 62) | 1 bit (63) |
Number type, namely Infinity, -Infinity and NaN, among which
Infinity: used to represent positive infinity values, generally refers to values greater than 1.7976931348623157 e 308;
-Infinity: used to represent a value of negative infinity, generally refers to a number less than 5e-324;
NaN : Not a number (abbreviation of Not a Number), used to represent invalid or undefined mathematical operation structures, such as 0 divided by 0.
Tip: If the result of a certain calculation exceeds the value range of the Number type in JavaScript, then the number will automatically be converted to infinity, with positive numbers being Infinity and negative numbers being -Infinity. .
Precision
Integers (without decimal point or exponent notation) are up to 15 digits.
var x = 999999999999999; // x 为 999999999999999 var y = 9999999999999999; // y 为 10000000000000000
The maximum number of decimal digits is 17, but floating point operations are not always 100% accurate:
var x = 0.2+0.1; // 输出结果为 0.30000000000000004
[Related recommendations: javascript video tutorial, webfrontend】
The above is the detailed content of What do javascript numbers represent?. For more information, please follow other related articles on the PHP Chinese website!