CFLib.org – Common Function Library Project

journeyCost(miles, mpg, ppl)

Last updated October 8, 2010

author

Dave Hill

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Calcualte the cost of a car journey based on miles traveled, your car's MPG and the cost of fulel per litre. Defaults set to UK values.

Return Values:
Returns a number.

Example:

<cfoutput>#journeycost(240,43,110.9)#</cfoutput>

Parameters:

Name Description Required
miles Miles traveled. Yes
mpg Miles per gallon. Yes
ppl Price per liter. Yes

Full UDF Source:

/**
 * Calculates the cost of a car journey.
 * 
 * @param miles 	 Miles traveled. (Required)
 * @param mpg 	 Miles per gallon. (Required)
 * @param ppl 	 Price per liter. (Required)
 * @return Returns a number. 
 * @author Dave Hill (write2dave@gmx.co.uk) 
 * @version 1, October 8, 2010 
 */
function journeyCost(miles,mpg,ppl) {
	var litresInGallon = 4.54;
	var cost = ( miles / mpg ) * litresInGallon * ( ppl / 100 );
	return decimalFormat(cost);
}
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