据我所知,一微秒是 1/1000000 秒(百万分之一)。 但是出于某种原因,我的 php.exe v5.4.12 x64(Windows 7 x64 上的 CLI)似乎“认为”它实际上是 1/10000th(千分之一)。
如果我运行以下 php 脚本:
<?php
while(true)
{
echo microtime(true)."\r";
}
?>
我在屏幕上看到的计数器永远不会超过 .9999。 从1381994204.9999跳到1381994205.0
昨晚我在写一个计算到一秒的脚本时发疯了,在意识到这一点后,我改变了公式,将 microtime(true) 输出除以 10000 而不是 1000000,它运行得很好......
最佳答案
通过将参数设置为 true
,您将获得一个浮点值——精度有限。 1381994986.3488
有 14 位有效数字,这是您通常使用 float 得到的数字:
“The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format).”
当不设置参数时,您可以看到您获取的值实际上是微秒 - 但您获取的是字符串形式。
关于php - 为什么 PHP 说微秒是 1/10000 秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19420585/