0

I have been looking around the web for this but cannot really find a good answer. I have a small site search and I want to display the time it took the mysql query to execute (similar to Google). I've been trying to use microtime() but I get huge strings like 1.342524564267782e25... I just want a simple digit with two decimals following (0.15). Thanks in advanced.

Starx
  • 77,474
  • 47
  • 185
  • 261
4WebDev
  • 85
  • 3
  • 9

2 Answers2

4

Use round to fix the decimal points

$time = microtime();
echo round($time, 2);
Starx
  • 77,474
  • 47
  • 185
  • 261
  • There's also `sprintf('%0.2f', $time)` and the like. PHP has LOTS of options for formatting numbers. – Marc B Apr 07 '12 at 17:16
2
$ms = microtime(true);
mysql_query($sql);
$ms = microtime(true) - $ms;
echo $ms.' secs'; //seconds
echo ($ms * 1000).' millisecs'; //millseconds