Causes of equal string

Source: Internet
Author: User
Why does PHP think the two strings are equal?
If ("03E-004611" = "36E-008026") echo 'Equality ';


Reply to discussion (solution)

This post was last edited by xuzuning at 17:10:29, January 8 ,.

var_dump("03E-004611"=="36E-008026"); //bool(true)var_dump(03E-004611, 36E-008026); //float(0) float(0)var_dump("03E-004611"==="36E-008026"); //bool(false)

A string composed of digits. it is converted to a numerical value before comparison.

Why does PHP think the two strings are equal?
If ("03E-004611" = "36E-008026") echo 'Equality ';
The upstairs explanation is not perfect, because you are using double quotation marks, and you are composed of digits, which can be executed in double quotation marks. this is a characteristic of php, if it is changed to single quotes, it will be different.

Because E is the 10 screen operation "03E-004611", it is infinitely close to 0 when it is converted to the number of points, 3 * pow (10,-4611), less than this high precision, so it's all 0.

Long knowledge


Why does PHP think the two strings are equal?
If ("03E-004611" = "36E-008026") echo 'Equality ';
The upstairs explanation is not perfect, because you are using double quotation marks, and you are composed of digits, which can be executed in double quotation marks. this is a characteristic of php, if it is changed to single quotes, it will be different.
The same is true for single quotes.

This has nothing to do with whether it is in a single double quotation mark!
Just a cognitive question about scientific notation

You said I have tried 90A-904611 and 36E-008026. These two strings are not equal.
Among them, 36E-008026 can be regarded as scientific notation, while 90A-904611 is not

Therefore, such numbers must be compared by strings instead of numerical values.

Rising posture

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.