Tattat
Tattat

Reputation: 15778

How to print a very small float value in php?

I have a function 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.

Upvotes: 1

Views: 2449

Answers (2)

Marc B
Marc B

Reputation: 360922

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.

Upvotes: 5

Amadan
Amadan

Reputation: 198566

printf('%f', $time);

Take a look at printf function

Upvotes: 0

Related Questions