PHP decimal calculation mode is too boring

Source: Internet
Author: User
Is PHP decimal calculation too boring? If (0.030 & nbsp ;! = & Nbsp; (0.530-0.500 + 0 + 0) {& nbsp; $ s & nbsp ;=& nbsp; 0.530-0.500 + 0 + 0; & nbsp; $ s & nbsp; = & nbsp; 0.03 & n is the calculation method of PHP decimal places too boring?
If (0.030! = (0.530-0.500 + 0 + 0 ))
{
$ S = 0.530-0.500 + 0 + 0;
$ S = 0.03-$ s;
}


Which is not equal ??
Not 0 After subtraction

Is PHP an alien computing method? Share:
------ Solution --------------------
Reference:
Quote: reference:

Please learn more about floating point numbers.

$ F = (0.530-0.500 + 0 + 0) * 1000;
$ A = (0.030*1000 );

$ Ssa = doubleval ($ a)-doubleval ($ f );

In this case, all of them are wrong... how does he calculate them?


This is not only true for php, but also for JAVA.
So there are two methods for PHP 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;
}
Add up the variable's double quotation marks.
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.