JavaScript you don't know about those things! (Digital computing-metamorphosis)

Source: Internet
Author: User
Tags decimal to binary

Javascript:alert (0.1 + 0.2)  

What would you think if you saw such a question? Everyone is sure the first reaction is 0.3, but considering I've already asked! I'll write an article about that naïve answer?

And then the people started torturing themselves, could it be 0.10.2?

And the results are still very windy.

0.30000000000000004

Come again, 0.1+0.7.

0.7999999999999999

This is due to the precision problem caused by the conversion of decimal to binary! Because the computer performs binary arithmetic, this accuracy error cannot be avoided when a decimal number cannot accurately convert the binary number. If this is a simple reason to describe or confusing, then go to the specific description behind the article!

And then, interesting thing, another interesting one.

parseint (0.0000008)

What's the result, you say 0, I say 8, and you say it's 8.

parseint (0.08)

Then this you say is 8, but I say 0 ... I think you're in a mess.

I searched for her 1100 degrees .... And then find the results

Many languages have precision problems with both floating-point and shaping operations '
Just maybe JS's a little bit more

Recognize the floating point arithmetic of javascript

The students who have studied JS know that the numbers in JS are represented by floating-point number, and the double-precision floating-point numbers are indicated using IEEE 754 standard.

 IEEE 754 Standard floating-point number Introduction (Oh, this is the University of the composition of the reason for the knowledge of learning OH)

IEEE 754 specifies two basic floating-point formats : single-precision and double-precision.

The IEEE single-precision format has a valid digital precision (containing symbol number) and occupies a total of three digits.

IEEE double-precision format has a valid numeric precision (including symbol number) in the single digit and occupies a total of four bits.

Description: The basic floating-point format is a fixed format, and the corresponding decimal valid digits are 7-bit and 17-bit respectively. The basic floating-point format corresponds to a C + + type of float and double.

JavaScript you don't know about those things! (Digital computing-metamorphosis)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.