CFLib.org – Common Function Library Project

RoundSigFig(fInput, iDigits)

Last updated October 24, 2003

author

jason snyder

Version: 2 | Requires: CF5 | Library: MathLib

Description:
Rounds a number to a specified number of significant digits.

Return Values:
Returns a numeric value.

Example:

<CFSET iOrigNo=10.5660>
<cfoutput>
Original=#iOrigNo#<br> 
After RoungSigFig=#RoundSigFig(iOrigNo, 4)#
</cfoutput>

Parameters:

Name Description Required
fInput Number to round. Yes
iDigits Number of significant digits to return. Yes

Full UDF Source:

/**
 * Rounds a number to a specified number of significant digits.
 * 
 * @param fInput      Number to round. (Required)
 * @param iDigits      Number of significant digits to return. (Required)
 * @return Returns a numeric value. 
 * @author jason snyder (jason.snyder@trw.com) 
 * @version 2, October 24, 2003 
 */
function RoundSigFig(fInput, iDigits) 
{
  //Local Variables
  var iLog = 0;
  var iTemp = 0;
  var fReturn = 0;

  //Execution
  if (fInput NEQ 0) { //If not zero round to significant digits.
    iLog=Int(Log10(Sgn(fInput)*fInput+0.0));
    iTemp=Round(fInput / (10^(iLog-iDigits+1)));
    //return(Log10(fInput+0.0)); //Debugging
    fReturn=evaluate(iTemp*(10^(iLog-iDigits+1)));
  } //End (Round to significant digits.)
  Return(fReturn);
} //End (RSigFig)

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

Created by Raymond Camden / Design by Justin Johnson