Parse unexpected exceptions in int conversions such as intval () in PHP. Let's take a look at the following online test code: Copy the code as follows :? Php $ a9.45 * 100; var_dump ($ a); var_dump (intval ($ a); $ a945 * 1.00; var_dump ($ a); var_dump (intval ($ )) let's take a look at the following online test code:
The code is as follows:
$ A = 9.45*100;
Var_dump ($ );
Var_dump (intval ($ ));
$ A = 945*1.00;
Var_dump ($ );
Var_dump (intval ($ ));
?>
Running result: float (945) int (944) float (945) int (945)
This code tells the results, but many people still don't understand it. this doesn't explain why unexpected transformations happen.
All the online statements about this situation are ambiguous. Here is a simple explanation:
The number 9.45 is shown here, but it is not in the machine, but 44999999999999999 .... Therefore:
9.449999*100 = 944.9999. So you can understand it? Intval removes the ending number directly. this is the name of Shenma. in this case, intval and floor () functions are similar. Haha. This is something I didn't notice before. I didn't notice that intval will be rounded down.
And 1.00 is nothing like 1.0099999, so 945*1.00 will have a float 945. the intval transformation will naturally not happen 944.
There are also some typical questions, such as intval (0.1 + 0.7) * 10) equals 7 rather than 8. This is all true. Okay. This is a simple example. At least it is much better than a lot of Alibaba Cloud on the Internet.
The pipeline code is as follows :? Php $ a = 9.45*100; var_dump ($ a); var_dump (intval ($ a); $ a = 945*1.00; var_dump ($ ); var_dump (intval ($ ))...