Rounding to certian decimal point spots

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
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Rounding to certian decimal point spots

Post by warriors2003 »

here is my next little minor dilema:

Someone helped me out earlier with a MATH FUNCTIOn,,awesome thanks!!! Now for the average, it's a baseball average and i would like to stop it at .123 no more then that third decimal spot. I have did some reading, and might have to you liek a 'ceil" function?? Don;t know how to quite do that,,but i figure I will prolly need to put something in the echo and it probably is somethign really easy I'm too dumb to figure out :D

Here is what I have,,wodnering where to put the rounding function and what exactly I am looking for to put in:


<?

$result = mysql_query ("SELECT SUM(hr) as hrSum, AVG(avg) as avgAvg from hit WHERE team='Ana'");

?>

while ($row = mysql_fetch_array($result))
{
echo <td><b>$row[hrSum]</b></td><td><b>$row[avgAvg]</b></td></tr>";

=========================================
Man you guys are awesome, I have leaped over some major headaches that have stumped me for a few weeks, and you guys are always helping!!! Thanks so much!!!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

hmm:


$number = round($row[hrSum], 3);
echo $number;
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Looks like it would work,,but having trouble incorportating that with what I already have,,can i put that isnide the avgAvg echo i laready have somehow??

Thanks in advance
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

or sql version:

Code: Select all

select blah, blah, blah, round(avg(avg), 3) from ...........
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Weirdan wrote:or sql version:

Code: Select all

select blah, blah, blah, round(avg(avg), 3) from ...........
that would be a better way in my eyes, let MySQL do the work.

but yes u could, any number u pull from the $row from the array can be used

round ($row['avgAvg'], 3); I saw the sum n didnt bother reading you have the average.
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Ok guys I can't seem to get it to work. I think I have somethign wrong in the sql statment.


("SELECT SUM(hr) as hrSum, AVG(avg) as avgAvg round(avg(avg), 3) from hit WHERE team='Ana'");

Most likely in the backend where the avg is probably an extra () or the comma..I know its probably something little
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

("SELECT SUM(hr) as hrSum, AVG(avg) as avgAvg round(avg(avg), 3) from hit WHERE team='Ana'");

change:

("SELECT SUM(hr) as hrSum, round(AVG(avg), 3) as avgAvg from hit WHERE team='Ana'");
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Boooooya !!!! Hoot hoot!!! Once again you guys prove to be gurus!!!! Thanks a million!!!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

:P
Post Reply