intervalRound(nNumber, nInterval[, bOption])
Last updated July 21, 2005
Version: 1 | Requires: CF5 | Library: MathLib
Description:
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.
Example:
<cfoutput>
IntervalRound(83,25): #IntervalRound(83,25)#
IntervalRound(149,75,0): #IntervalRound(149,75,0)#
IntervalRound(149,75,1): #IntervalRound(149,75,1)#
</cfoutput>
Parameters:
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 (rob@robrusher.com)
* @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);
}
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