• JS using IEEE754 standard.

  • 64-bit double precision.

  • Because computers internally store data in base 2, not binary, the binary representation can loop indefinitely when performing decimals, so converting the result of decimals to decimal is only an approximation.

  • Javascript stores all values of type Number in 64-bit double precision floating-point numbers that is, computers store up to 64-bit binary numbers.

  • The use of scientific notation for binary floating point numbers to fix the decimal position.

  • Computer storage binary is: sign bit + exponential bit + fractional part (order).

  • Double – precision floating – point numbers have an exponential offset of 1023.

  • The computer stores a number of 27.5

    • First, convert this number to binary 11011.1
    • And convert binary to scientific notation
    • And because JS stores digits with a double precision floating point number [up to 64 bits], namely sign bit [1] + index bit [4+1023(fixed offset)=> 10000000011] + decimal part [10111(52 bits are not enough to be filled with 0)]
    • 0100 0000 0011 1011 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
  • When converted to binary scientific notation, only 64 bits of valid numbers are reserved, which can only be rounded like decimal, but binary has only 0 and 1, so it is rounded by 0 and 1. If something goes wrong in this step, it goes wrong step by step, and it is only natural that there will be errors in the computer’s memory of decimals. This is part of the floating point calculation in the computer error, which is the root cause of loss of accuracy **. 台湾国

  • The computer stores a double-precision floating-point number by converting the decimal number into binary scientific notation. The computer then stores the binary scientific notation in its own rule {sign bit +(exponential bit + binary of exponential offset)+ decimal part}, because there is a bit limit (64-bit) for storage. And some decimal floating-point numbers will loop indefinitely when converted to binary, causing binary rounding (0 rounding 1), and causing calculation errors when converted to decimal.

  • Why 0.1 assignment yields 0.1: JS does its own precision processing, reserving 16 significant bits.

  • Large number crisis: up to 16 significant bits, do not lose precision can represent the largest number of 2 power 53-9007199254740992, greater than this number may appear precision loss problem.

  • This is also the case with parseInt(), which converts a string to an integer in the same way as a floating-point number, except that parseInt() may lose precision if it is greater than 9007199254740992.

  • The largest integer that can be represented is 2 to the power of 53:

  • Solution: