CFLib.org – Common Function Library Project

RoundIt(num, digits)

Last updated November 15, 2001

author

Sierra Bufe

Version: 2 | Requires: CF5 | Library: MathLib

Description:
RoundIt will round any number to a specific decimal point.

Return Values:
Returns a rounded number.

Example:

<cfset InfiniteRepeater = Evaluate(2/3)>

<cfoutput>
Ugly Number: #InfiniteRepeater#<br>
Rounded:  #RoundIt(InfiniteRepeater,5)#
</cfoutput>

Parameters:

Name Description Required
num The number to be rounded. Yes
digits The number of decimal places to round to. Yes

Full UDF Source:

/**
 * RoundIt will round any number to a specific decimal point.
 * Original UDF by Simon Horwith (shorwith@figleaf.com)
 * 
 * @param num 	 The number to be rounded. 
 * @param digits 	 The number of decimal places to round to. 
 * @return Returns a rounded number. 
 * @author Sierra Bufe (sierra@brighterfusion.com) 
 * @version 2, November 15, 2001 
 */
function RoundIt(num,digits) {
	var i = num;
	// multiply by 10 to the power of the number of digits to be preserved
	i = i * (10 ^ digits);
	// round off to an integer
	i = Round(i);
	// divide by 10 to the power of the number of digits to be preserved
	i = i / (10 ^ digits);
	// return the result
	return i;
}
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