Strange results with script execution time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Strange results with script execution time

Post by toasty2 »

I'm getting strange results like 7.5101852416992E-005 with the following code:

Code: Select all

<?php
$t1 = explode(' ',microtime());
$t1 = $t1[1] + $t1[0];

// Do stuff

$t2 = explode(' ', microtime());
$t = ($t2[1] + $t2[0]) - $t1;
echo $t;
?>
(That is my real script) The same code worked fine on a bigger script. (On a bigger script I get 0.00052094459533691)
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

7.5101852416992E-005 = 0.000075101852416992
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I asked about this last night. Use number_format() to format the result.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

number_format() gives me 0
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

How did you use number format? Did you read the manual?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What parameters did you use in number_format?
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

None except for the number. Now I realize that will show up as 0 (no decimals). I'm not really sure how to use number_format(), the manual only explains the aesthetics for showing numbers, I just want it to be converted to a readable number (such as 0.0025354436 etc).
Last edited by toasty2 on Sat Jun 30, 2007 5:31 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

What does the second parameter of number_format do per the manual?
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

:lol: Thanks, sometimes the arguments list tells you more than the descriptions about them.
Post Reply