The floating point number X.1 in C/C ++

Source: Internet
Author: User

I saw this question in a topic just now.
Cannot be correctly divided into N.1 floating point numbers

After debugging, we found that
When reading a floating point number, 2.1 or 3.1,
The actual values are 2.0999999 and 3.099999.

The reason is that because 0.1 is represented as a circular decimal number in binary format, it cannot be correctly expressed. 0. 0001100110011 ....
Therefore, it is 0.09999999

======================================

So when we split up floating-point numbers,
You can first read the data in a string and then split it.
Of course, this is just my idea. Maybe there is a better way.

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.