What If You Want To Round Down?

ColdFusion’s round() function rounds up. What if you want to round down? Use this:

<cffunction name="roundDown" output="no">
<cfargument name="target" type="numeric" required="true"/>
<cfreturn abs(round((arguments.target * -1)))/>
</cffunction>

Example:

round(1.1) = 1
roundDown(1.1) = 1

round(1.5) = 2
roundDown(1.5) = 1

round(1.6) = 2
roundDown(1.6) = 2

Addition:

Bill pointed out that the function above doesn’t work with negative numbers. This one does. Thanks, Bill!

<cffunction name="roundDown" output="no">
<cfargument name="target" type="numeric" required="true"/>
<cfreturn (round((arguments.target * -1))) * -1/>
</cffunction>

Example:

roundDown(-1.5) = -2