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.
Trimming Excess Digits After Calculations
Moderator: General Moderators
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
?>