About PHP floating-point arithmetic

Source: Internet
Author: User


To ask if the true and false is random, or there is a regular, thank you.

Reply content:


To ask if the true and false is random, or there is a regular, thank you.

Take a look at a blog post I wrote before.

Code Puzzle (iv)-floating point (from surprise to thinking)

Many floating-point numbers cannot be represented in a computer, and others can be represented, but not accurately expressed.

Add, if you want to do floating-point arithmetic in PHP, use binary Calculator, that is, Bcmath extension

With the round function, see: http://www.tantengvip.com/2015/08/php-float/

If you use the float/double format defined by the IEEE754 standard, unfortunately, you cannot store 0.1 accurately, because the simple binary cannot accurately express this decimal (do not believe you try ~). Similarly, in the calculation of floating-point numbers, it is often unavoidable to lose some precision.

See Shell Technology: Android Calculator low-level error? It's all a binary mess!

For reference: Http://acm.whu.edu.cn/starter/problem ...

Recommended landlord Buy this "in-depth understanding of computer system" to see, the second chapter on the information about how the data stored in the computer, after reading you will understand.

Look at these answers, it's all very well, thank you.

  • 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.