Traditional Culture Encyclopedia - Traditional virtues - The problem of PHP module taking
The problem of PHP module taking
I asked a friend and found a problem: when floating p>< is converted to integer:
<; ? php
$a = 9.45*1;
var_dump($a);
var_dump(intval($a));
$a = 945*1.;
var_dump($a);
var_dump(intval($a)); >
the running results are as follows:
float (945) int (944) float (945) int (945)
both are floating-point 945, one is converted to 944 and the other is converted to 955
Obviously, a simple decimal fraction like .1 or .7 cannot be converted into internal binary without losing a little precision. This will lead to confusing results: for example, floor((.1+.7)*1) usually returns 7 instead of the expected 8, because the internal representation of the result is actually similar to 7.9999 ...
This is related to the fact that it is impossible to accurately express some decimal fractions with finite digits. For example, 1/3 of the decimal system becomes .3333333.
so never believe that the floating-point number result is accurate to the last digit, and never compare whether two floating-point numbers are equal.
that is to say, 9.45*1 is similar to 944.9999
I hope the above explanation can help you. .
- Previous article:I want to be a pastry chef. Should I be an apprentice in a store? Still going to school?
- Next article:How to teach traditional culture?
- Related articles
- What are the advantages and disadvantages of concrete?
- What does the saying "Father and son eat at different tables, uncles and nephews do not drink together" mean?
- Wenling custom composition
- The History and Introduction of Go
- Examples of short stories about the Spring Festival
- New Year's Day is a legal holiday.
- Beijing Tongrentang Xing'an health care science and technology limited liability company Luannan branch of the production of drugs line
- Traditional Parenting in China and Parenting in the West
- Who can give me the names of some wines?
- Is the Redtory Creative Park open now?