Questions about new php students (closed on weekends)

Source: Internet
Author: User
Questions about new php students (closed on weekends) Echo (int) (0.1 + 0.7) * 10); // Display 7
Echo (int) (0.2 + 0.7) * 10); // Display 9
?>
Why is the first execution result not 8?


Reply to discussion (solution)

Floating point number accuracy

 printf('%0.16f',  (0.1+0.7) * 10 ); // 7.9999999999999991




Floating point number accuracy

 printf('%0.16f',  (0.1+0.7) * 10 ); // 7.9999999999999991



Without int, it is 8.
Echo (0.1 + 0.7) * 10); // Display 8

Echo (int) (0.1 + 0.7) * 10); // Display 7
In my understanding, the result in the right parenthesis is forcibly converted to the int type, that is, echo (int) 8;

That's what you got wrong.
(Int) is forcibly converted to an integer. at this time, only the fractional part is truncated and no other processing is performed.
Echo (int) 2.2; // 2
Echo (int) 2.9; // 2
Likewise
Echo (int) 7.9999999999999991; // 7

Echo (0.1 + 0.7) * 10; // 8
This is because php handles the rules based on valid numbers.

Float ?? Accuracy ??.
Http://segmentfault.com/q/1010000002123613

Problem 1: Resolved
Question 2: How can I debug a php project?

Open the error log.

?? ? Ann? Xdebug

Http://www.cnblogs.com/qiantuwuliang/archive/2011/01/23/1942382.html

Class A {function foo () {if (isset ($ this) {// $ this here refers to the class object? Echo '$ this is defined ('; echo get_class ($ this); echo ") \ n";} else {echo "\ $ this is not defined. \ n ";}}$ a = new A (); $ a-> foo (); // Output $ this is defined (A) echo'
'; A: foo (); // $ this is not defined


A: foo () and $ a-> foo () call the same method. why is the output different?

$ This is the instantiated object.

A: foo (); the class method is called statically.
Php 5.3 and later will have a Strict Standards-level error warning:
Non-static method A: foo () shocould not be called statically
Non-static methods cannot be called in static mode

Since you are a beginner, we recommend that you use php 5.4 or later, and the error check level is all
This makes it easy to form good habits.

$ This is the instantiated object.

A: foo (); the class method is called statically.
Php 5.3 and later will have a Strict Standards-level error warning:
Non-static method A: foo () shocould not be called statically
Non-static methods cannot be called in static mode

Since you are a beginner, we recommend that you use php 5.4 or later, and the error check level is all
This makes it easy to form good habits.

How can I tell if the company is a lie when I submit my resume on the market?

When replying, how can I determine whether the landlord is a lie?

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.