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
toasty2
Forum Contributor
Posts: 361 Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA
Post
by toasty2 » Sat Jun 30, 2007 4:34 pm
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)
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Sat Jun 30, 2007 4:48 pm
7.5101852416992E-005 = 0.000075101852416992
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Jun 30, 2007 4:54 pm
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 » Sat Jun 30, 2007 5:15 pm
number_format() gives me 0
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sat Jun 30, 2007 5:19 pm
How did you use number format? Did you read the manual?
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Sat Jun 30, 2007 5:23 pm
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 » Sat Jun 30, 2007 5:28 pm
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.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Jun 30, 2007 5:30 pm
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 » Sat Jun 30, 2007 5:32 pm
Thanks, sometimes the arguments list tells you more than the descriptions about them.