CFLib.org – Common Function Library Project

journeyCost(miles, mpg, ppl)

Last updated October 08, 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);
}

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

Created by Raymond Camden / Design by Justin Johnson