– Common Function Library Project

intervalRound(nNumber, nInterval[, bOption])

Last updated July 20, 2005


Rob Rusher

Version: 1 | Requires: CF5 | Library: MathLib

As an alternative to traditional rounding, this UDF allows you to set the round interval for a number. So with an interval set to 25, the number would round to 0, 25, 50,...

Return Values:
Returns a number.


IntervalRound(83,25): #IntervalRound(83,25)#
IntervalRound(149,75,0): #IntervalRound(149,75,0)#
IntervalRound(149,75,1): #IntervalRound(149,75,1)#


Name Description Required
nNumber The number to round. Yes
nInterval The number to round to. Yes
bOption Used to calculate percentage for rounding. No

Full UDF Source:

 * Rounds any real number to a user specified interval.
 * @param nNumber 	 The number to round. (Required)
 * @param nInterval 	 The number to round to. (Required)
 * @param bOption 	 Used to calculate percentage for rounding. (Optional)
 * @return Returns a number. 
 * @author Rob Rusher ( 
 * @version 1, July 20, 2005 
function intervalRound(nNumber, nInterval){
	var nMultipler = fix(nNumber / nInterval); // How many times does the interval go into intNumber
	var bOption = 0;

	if(arrayLen(arguments) GTE 3 AND arguments[3])
		if(((nNumber mod nInterval) / nInterval) gte .5) bOption = 1; // Calculate percentage for rounding option.

	return (nInterval * nMultipler) + (bOption * nInterval);
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson