CFLib.org – Common Function Library Project

MPGCalc(journeyStart, journeyEnd, liters)

Last updated October 8, 2010

author

Dave Hill

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);
    
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson