Page 1 of 1

Trimming Excess Digits After Calculations

Posted: Sat Feb 28, 2004 5:59 pm
by ut1205
I have a MYSQL Database which holds "Miles Per Gallon, etc" info on my vehicles.

I do queries to determine total fuel purchased, total miles driven, etc. and do division computations and post the result to a table.

When I do something like:

$AverMPG = $TotalMiles / $GalPurchased

Then print $AverMPG to a cell in my table I get a result like:
16.584752

Where and how do I trim it down to one or two numbers after the decimel.

Posted: Sat Feb 28, 2004 6:00 pm
by markl999

Posted: Sat Feb 28, 2004 6:30 pm
by ut1205
I sincerely appreciate your response but I have already been there and didn't understand it. I thought that I might a simple answer or someone who could explain it in "NewBee" terms.

Posted: Sat Feb 28, 2004 6:46 pm
by Dr Evil
Use one of these functions to shorten your number. For example with round, just add this after the average calculation:

Code: Select all

<?php
$AverMPG = round($AverMPG,2); //keeps only 2 digits 
?>

Posted: Sat Feb 28, 2004 7:09 pm
by ut1205
:D Thanks, That Works