CFLib.org – Common Function Library Project

RoundUpDown(input[, multiple][, direction])

Last updated June 27, 2002

author

Casey Broich

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Rounds a number up or down to the nearest specified multiple.

Return Values:
Returns a numberic value

Example:

<CFOUTPUT>
RoundUpDown(102): #RoundUpDown(102)#<BR>
RoundUpDown(102,10,"up"): #RoundUpDown(102,10,"up")#<BR>
RoundUpDown(102,10,"down"): #RoundUpDown(102,10,"down")#<BR>
</CFOUTPUT>

Parameters:

Name Description Required
input Number you want to round. Yes
multiple Multiple by which to round. Default is 5. No
direction Direction to round. Options are Up or Down. Default is Up No

Full UDF Source:

/**
 * Rounds a number up or down to the nearest specified multiple.
 * 
 * @param input 	 Number you want to round. (Required)
 * @param multiple 	 Multiple by which to round.  Default is 5. (Optional)
 * @param direction 	 Direction to round.  Options are Up or Down.  Default is Up (Optional)
 * @return Returns a numberic value 
 * @author Casey Broich (cab@pagex.com) 
 * @version 1, June 27, 2002 
 */
function RoundUpDown(input){
  var roundval = 5;
  var direction = "Up";
  var result = 0;

  if(ArrayLen(arguments) GTE 2) 
    roundval = arguments[2];
  if(ArrayLen(arguments) GTE 3) 
    direction = arguments[3];
  if(roundval EQ 0) 
    roundval = 1;

  if((input MOD roundval) NEQ 0){
     if((direction IS 1) OR (direction IS "Up")){
      result = input + (roundval - (input MOD roundval));
     }else{
      result = input - (input MOD roundval);
     }
  }else{
    result = input;
  }
  return result;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson