CFLib.org – Common Function Library Project

truncNumber(input[, decimals])

Last updated June 15, 2006

author

Tony Monast

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Cuts a number to a certain amount of decimal places without rounding.

Return Values:
Returns a number.

Example:

<cfoutput>#TruncNumber(3.646)#</cfoutput>

Parameters:

Name Description Required
input Decimal number. Yes
decimals Number of decimals to the right of the period. Defaults to 2. No

Full UDF Source:

/**
 * Cuts a number to a certain amount of decimal places without rounding.
 * 
 * @param input 	 Decimal number. (Required)
 * @param decimals 	 Number of decimals to the right of the period. Defaults to 2. (Optional)
 * @return Returns a number. 
 * @author Tony Monast (tony@ckm9.com) 
 * @version 1, June 15, 2006 
 */
function truncNumber(input) {
	var decimals = 2;
	var regex = "";
	var st = "";
	if(arrayLen(arguments) EQ 2) decimals = arguments[2];
	regex = "^\d*(.\d{1," & decimals & "})?";
	st = reFind(regex,input,1,true);
	return mid(input,st.pos[1],st.len[1]);
}
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