PHP3 math/date problem

From: Date: Sun, 09 Jul 2000 03:47:48 +0000
Subject: PHP3 math/date problem
Groups: php.general 
Request: Send a blank email to php-general+get-5579@lists.php.net to get a copy of this message
Below is a simple timer script that simply calculates the elapsed time from the query of a database until the answer is obtained and formatted. the function utime, I found somewhere...I just added the 4th line of the function so that the output time is only two decimal places .33 instead of .337895679 etc. The problem is this-- the variables $start and $end provide correctly formatted numbers 9631189.34 --however, when I subtract the two $end-$start the answer is always in 8 or 9 dec. places (for example 5.05896321) instead of two....I can't figure out why, the ans should be two dec places, automatically... I can reformat the answer..no problem, but I don't understand what's happening with the dec places and why. Note: The print statements are for debugging only, normally the numbers would be written to a log file. <? function utime() { $time = explode( " ", microtime()); $usec = (double)$time[0]; $sec = (double)$time[1]; $usec = substr($usec, 1, 3); return ($sec+$usec); } $start=utime(); Print("a....$start<br><br>"); /* there is a routine here to query a database and format the output */ $end=utime(); print("b...$end<br><br>"); $final=$end-$start; Print("The total time is..$final<br><br>"); ?>

« previous php.general (#5579) next »