CFLib.org – Common Function Library Project

splitNumber(number)

Last updated August 26, 2012

author

Darwan Leonardo Sitepu

Version: 1 | Requires: CF8 | Library: MathLib

Description:
Takes an numeric value and returns a struct with keys integer and decimal, each holding the relevant part of the original value.

Return Values:
Returns a struct with keys integer and decimal, containing the relevant parts of the original number

Example:

<cfset result = splitNumber(254.999989)>
<cfoutput>
Integer Value = #result.integer#<br /><!--- 254 --->
Decimal Value = #result.decimal#<br /><!--- 999989 --->
</cfoutput>

Parameters:

Name Description Required
number A numeric value to split into integer/decimal parts Yes

Full UDF Source:

/**
 * Splits a numeric value into integer and decimal parts
 * version 0.1 by Darwan Leonardo Sitepu
 * version 1.0 by Adam Cameron. Renamed function, simplified logic, fixed a data truncation bug, returns a struct rather than a query now.
 * 
 * @param number 	 A numeric value to split into integer/decimal parts (Required)
 * @return Returns a struct with keys integer and decimal, containing the relevant parts of the original number 
 * @author Darwan Leonardo Sitepu (dlns2001@yahoo.com) 
 * @version 1, August 26, 2012 
 */
public struct function splitNumber(required numeric number){
	var result = {};
	result.integer = listFirst(number, ".");
	if (listLen(number, ".") > 1){
		result.decimal = listRest(number, ".");
	}else{
		result.decimal = 0;
	}
	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