roundBy Function

Allows you to round U=Up, D=Down, A=Average to any factor, defaults to 1.

<!--- Rounding Routine --->
<cffunction name="roundBy" returntype="numeric">
	<cfargument name="value" type="numeric" required="True" />
	<cfargument name="factor" type="numeric" default="1" />
	<cfargument name="direction" type="string" default="A" />

	<cfset var result = 0 />
	<cfset var positive = True />

	<!--- Remember Sign --->
	<cfif value lt 0>
		<cfset positive = false />
		<cfset value = value * -1 />
	</cfif>
	
	<!--- Fix Floating Point Numbers --->
	<cfif listLen(value, ".") gt 1>
		<cfset value = listGetAt(value, 1, ".") + precisionEvaluate('.' & left(listGetAt(value, 2, "."), 10)) />
	</cfif>

	<!--- Rounding Direction --->
	<cfswitch expression="#direction#">
		<!--- U: Round Up --->
		<cfcase value="U">
			<cfset result = ceiling(precisionEvaluate(value / factor)) * factor />
		</cfcase>
		<!--- D: Round Down --->
		<cfcase value="D">
			<cfset result = int(precisionEvaluate(value / factor)) * factor />
		</cfcase>
		<!--- A: Round Automatic --->
		<cfdefaultcase>
			<cfset result = round(value / factor) * factor/>
		</cfdefaultcase>
	</cfswitch>

	<cfif positive eq false>
		<cfset result = result * -1 />
	</cfif>
	
	<cfreturn val(result) />
</cffunction>