Page 1 of 1

Rounding to certian decimal point spots

Posted: Tue Mar 30, 2004 8:21 pm
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!!!

Posted: Tue Mar 30, 2004 8:33 pm
by tim
hmm:


$number = round($row[hrSum], 3);
echo $number;

Posted: Tue Mar 30, 2004 8:40 pm
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

Posted: Tue Mar 30, 2004 8:40 pm
by Weirdan
or sql version:

Code: Select all

select blah, blah, blah, round(avg(avg), 3) from ...........

Posted: Tue Mar 30, 2004 8:51 pm
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.

Posted: Tue Mar 30, 2004 9:02 pm
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

Posted: Tue Mar 30, 2004 9:05 pm
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'");

Posted: Tue Mar 30, 2004 9:07 pm
by warriors2003
Boooooya !!!! Hoot hoot!!! Once again you guys prove to be gurus!!!! Thanks a million!!!

Posted: Tue Mar 30, 2004 9:08 pm
by tim
:P