MPGCalc(journeyStart, journeyEnd, liters)
Last updated October 08, 2010
Version: 1 | Requires: CF5 | Library: UtilityLib
Description:
Calculate the Miles Per Gallon (MPG) for your vehicle. Defaults set to UK values.
Return Values:
Returns a number.
Example:
<cfoutput>
Your MPG is #mpgcalc(4995,5235,25)#
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
journeyStart | Miles on odometer at start. | Yes |
journeyEnd | Miles on odometer at end. | Yes |
liters | Liters of gas consumed. | Yes |
Full UDF Source:
/**
* Calculate a vehicles Miles Per Gallon (MPG)
*
* @param journeyStart Miles on odometer at start. (Required)
* @param journeyEnd Miles on odometer at end. (Required)
* @param liters Liters of gas consumed. (Required)
* @return Returns a number.
* @author Dave Hill (write2dave@gmx.co.uk)
* @version 1, October 8, 2010
*/
function mpgcalc(journeyStart,journeyEnd,litres) {
var litresInGallon = 4.54;
var miles = journeyEnd - journeyStart;
var gallons = litres/litresInGallon;
var mpg = miles/gallons;
return decimalFormat(mpg);
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016