I have not read the manual about floating point number comparison.

Source: Internet
Author: User
For floating point number comparison, the manual does not understand; $ a & nbsp; 1.11; $ B & nbsp; 1.11; if ($ a $ B) {The result is true.} isn't it true that two floating point numbers are equal? What does it mean? cannot the calculated floating point numbers be compared? & Nbsp; ------ solution ---------------------- it is not to say that we should not compare, but that the manual does not understand the accuracy of the comparison of floating point numbers;
$ A = 1.11;
$ B = 1.11;

If ($ a = $ B ){
// The result is true;
}

Isn't it true that two floating point numbers are equal?
What does it mean? cannot the calculated floating point be compared?
------ Solution ----------------------
This is not to say that we do not want to compare, but because of the precision, the two seemingly identical numbers are not equal in comparison.
You can compare two numbers with the same precision. Of course there is no problem.


------ Solution ----------------------
It is not incomparable, but inaccurate.

For example:

$a = 1.1000000000000000001;
$b = 1.1000000000000000011;

if($a==$b){
echo 'equal';
}else{
echo 'not equal';
}


Output equal
------ Solution ----------------------
$ A = 1.00000000000000001;
$ B = 1.00000000000000002;
Var_dump ($ a = $ B); // bool (true) is actually equal

$ S = pack ('F', $ );
For ($ I = 0; $ I Echo PHP_EOL;

$ S = pack ('F', $ B );
For ($ I = 0; $ I Echo PHP_EOL;

They used to save the data in the computer.
00000000 00000000 10000000 00111111
00000000 00000000 10000000 00111111

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.