Copy Code code as follows:
<?php
List ($usec, $sec) = Explode (', microtime ());
$timer = (float) $usec + (float) $sec;
mysql_query ($query, $active _db);
List ($usec, $sec) = Explode (', microtime ());
$stop = (float) $usec + (float) $sec;
$diff = $stop-$timer;
?>
$stop and $timer are the floating-point numbers that are converted, and in most cases the results of the echo $stop and Echo $timer are the same as the naked eye, but they are not stored the same in the computer, so the result is not 0, and may also be negative.
The PHP manual prompts:
Floating-point precision:
Obviously a simple decimal score like 0.1 or 0.7 cannot be converted to an internal binary format without losing a little bit of precision. This can result in confusing results: for example, Floor (0.1+0.7) *10 usually returns 7 rather than the expected 8 because the internal representation of the result is actually similar to 7.9999999999 ....
This is related to the fact that it is impossible to accurately express certain decimal points with a finite number of digits. For example, the decimal 1/3 becomes 0.3333333. . .。
So never believe that floating-point numbers are accurate to the last one, and never compare two floating-point numbers for equality. If you do need higher precision, you should use arbitrary precision mathematical functions or GMP functions.