CFLib.org – Common Function Library Project

Convert2Number(strVal)

Last updated November 15, 2002

Version: 1 | Requires: ColdFusion 5 | Library: MathLib

 
Rated 0 time(s). Average Rating: 0

Description:
This function will take any string and strip out all characters that are not (-.0123456789) and will then determine it's numeric value.

Return Values:
Returns a number.

Example:

view plain print about
Convert2Number($3,456.78) will return the numeric value 3456.78

Parameters:

Name Description Required
strVal Value to convert. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Converts any numeric string (even ones with currancy symbols to a number).
 * 
 * @param strVal      Value to convert. (Required)
 * @return Returns a number. 
 * @author Glenn Wilson (glenn.wilson@quotegen.com) 
 * @version 1, November 15, 2002 
 */

function Convert2Number(StrVal){
  var regStr = "[^/.0123456789-]";
  return Val(REReplace(StrVal,regStr,"","all"));
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson