Analysis of the double hexadecimal problem in JAVA Basics

Source: Internet
Author: User

 
Recently, I saw a younger brother in the Group asking for help: int a = 58; double B = 0.35; double c = a * B; why is it equal to 20.29999999999997 instead of %3www.2cto.com? I think about a cigarette on the computer, why? I have been studying java for two years. How can I answer this question suddenly? I have repeatedly thought out my ideas. Please discuss them together! 1. First, you must understand that the computer only recognizes 0 and 1. 2. in java, the floating point representation is represented according to the IEEE754 standard. Generally, the number (s) is 1 bit, and the order (E) is different depending on the floating point type, the ending number (M) is also different in the number of digits of different types, so the total length of the number of digits that a computer can represent is limited to 32-bit, 64-bit, 80-bit. 3. You must understand that when decimal points are converted to binary values, some decimal points cannot be fully converted and only approximate values can be taken. 4. for example, 0.35 is converted to binary 0. 01100 .......... if this binary code is converted into a decimal number, it cannot be expressed as 0.35. It can only be infinitely close to 0.35. this is the so-called loss of precision, because some decimal places cannot be converted to binary, and some decimal places are lost.

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.