PHP decimal Calculation mode It's too much for dad.

Source: Internet
Author: User
How do you calculate PHP decimals?
if (0.030! = (0.530-0.500+0+0))
{
$s = 0.530-0.500+0+0;
$s = 0.03-$s;
}


This is not equal??
It's not 0 after subtracting.

Is this PHP an alien calculation method?

Share to:


------Solution--------------------
References:
Quote: References:

Would you please cram your knowledge about floating-point numbers?

$f = (0.530-0.500+0+0) *1000;
$a = (0.030*1000);

$ssa = Doubleval ($a)-doubleval ($f);

It's wrong to write ... How did he figure that out?


This is not only PHP, Java also has a phenomenon
So PHP has 2 ways to solve floating-point numbers.
One is
if (0.030! = (0.530-0.500+0+0))
{
$s = 0.53-0.5;
$s = 0.03-"$s";
Echo $s;
}
Put the variable in double quotes and it's OK.
Another way is to use the round function.
  • 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.