开发者

How to print a very small float value in php?

I have a functi开发者_开发知识库on that print calculate the loading time of each page:

function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
 $time_start = microtime_float();

$time_end = microtime_float();
$time = $time_end - $time_start;

but when I echo the $time, I get something like this:

5.60283660889E-5

But I would like to have a value like 0.000000000000xxxx, how can I convert this? Thank you.


There's no need for your "float" function, just do

$time_start = microtime(TRUE);

which returns the value as float.

To display the decimals, try

printf('%.16f', $time);

which tells PHP to format a float with 16 decimal places of output.


printf('%f', $time);

Take a look at printf function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜