RoundIt(num, digits)
Last updated November 15, 2001
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;
}
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