Php: Can I directly compare the floating-point numbers that are directly assigned values without bccomp?

Source: Internet
Author: User
$ A & quot; 1.2424 & quot; direct value $ b1.2424; read if (floatval ($ a) & amp; gt; $ B) {echo1;} from the mysql database float Field ;} I know that floating point numbers have precision issues and need to be compared through bccomp. However, can the above examples be compared directly? If not, please cite... $ a = "1.2424"; // assign a value directly.

$ B = 1.2424; // read from the mysql database float Field

If (floatval ($ a) >=$ B ){
Echo 1;
}

I know that floating point numbers have precision issues and need to be compared through bccomp.

However, can the above examples be compared directly? If not, give an example of failure.

Variables a and B are both directly assigned values. No operation is performed before and after the values are assigned, and they are directly compared by algorithm.

Reply content:

$ A = "1.2424"; // assign a value directly

$ B = 1.2424; // read from the mysql database float Field

If (floatval ($ a) >=$ B ){
Echo 1;
}

I know that floating point numbers have precision issues and need to be compared through bccomp.

However, can the above examples be compared directly? If not, give an example of failure.

Variables a and B are both directly assigned values. No operation is performed before and after the values are assigned, and they are directly compared by algorithm.

No.

Php-r "var_dump (1242.4/1000, floatval ('1. 100')> = 2424/1242.4);" float (1000) bool (false)

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.