Why are the two return methods of the microtime() function in PHP different in precision?
習慣沉默
習慣沉默 2017-05-24 11:33:37
0
1
544

Environment:
CentOS 7.3.1611
PHP 7.1.3

Code:

Output:

string(21) "0.23337700 1495449772" float(1495449772.2334)

Question:
Run the code repeatedly and get the same result.
It is easy to understand that it is easy to understand to output an 8-digit millisecond value in the form of a string. Anyway, the last two digits are always 0. When output as a floating point number, the accuracy is controlled to four digits. What is the reason?

Additional verification:
Executephp -r "echo ini_get('precision'), PHP_EOL;"The output result is14, which is obviously not about floating point in PHP The precision setting affects the output of microtime(). The "microtime" keyword is not found in php.ini. It seems that there are no special settings that affect the output accuracy.

I'm dizzy, and I'm looking forward to the expert's advice.

習慣沉默
習慣沉默

reply all (1)
曾经蜡笔没有小新

ini_get('precision')A control accuracy of 14 means:

float(1495449772.2334) has 14 digits in total, 10 digits before the decimal point and 4 digits after the decimal point. It does not mean 14 digits after the decimal point.

Let’s take a look at the results of the facet code.

ini_set('precision', 18); var_dump(microtime()); var_dump(microtime(true));
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!