Comparison of long numeric strings

Source: Internet
Author: User
Comparison of long numeric strings This post was last edited by anyilaoliu from 2013-12-1315: 04: 43 such as Question & nbsp; encountered such a problem $ a & nbsp; = & nbsp; "222111565652521142"; $ B & nbsp ;=& nbsp; "22211156565252113 comparison of long numeric strings
This post was last edited by anyilaoliu at 15:04:43, January 13 ,.
This problem occurs.


$a = "222111565652521142";
$b = "222111565652521139";
$c = 222111565652521142;
$d = 222111565652521139;

var_dump($a);
echo "
";
var_dump($b);
echo "
";
var_dump($c);
echo "
";
var_dump($d);
echo "
";

if ($a == $b) {
echo 3;
}else{
echo 31;
}
echo "
";

if ($c == $d) {
echo 4;
}else{
echo 41;
}
echo "
";


The result is





string '222111565652521142' (length=18)


string '222111565652521139' (length=18)


float 2.2211156565252E+17


float 2.2211156565252E+17



31
4


The question is, how can we compare the two in the second case?

Problem 2: The two groups of numbers read from the database are displayed as string (18) after var_dump, but the comparison result is the opposite of the above example, the comparison between the two strings is also passed.

Solution sharing: More

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.