View comments | RSS feed

IsNumeric

Description

Determines whether a string can be converted to a numeric value. Supports numbers in U.S. number format. For other number support, use LSIsNumeric.

Return value

True, if string can be converted to a number; otherwise, False.

Category

Decision functions

Syntax

IsNumeric(string)

See also

IsBinary

Parameters

Parameter Description
string
A string or a variable that contains one.

Example

<h3>IsNumeric Example</h3>
<cfif IsDefined("FORM.theTestValue")>
  <cfif IsNumeric(FORM.theTestValue)>
  <h3>The string <cfoutput>#DE(FORM.theTestValue)#</cfoutput> can be 
converted to a number</h3>
  <cfelse>
  <h3>The string <cfoutput>#DE(FORM.theTestValue)#</cfoutput> cannot be 
converted to a number</h3>
  </cfif>
</cfif>

<form action = "isNumeric.cfm">
<p>Enter a string, and find out whether it can be evaluated to a numeric value.

<p><input type = "Text" name = "TheTestValue" value = "123"> 
<input type = "Submit" value = "Is it a Number?" name = "">
</form>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


mocax said on Jul 29, 2005 at 3:17 AM :
Note that the function returns false when the "number" gets large enough.
Like 1797693134862315807937289714053034150799341327100378269361737789804449682927647509466490179775872070963302864166928879109465555478519404026306574886715058206819089020007083836762738548458177115317644757302700698555713669596228429148198608349364752927190741684443655107043427115596995080930428801779041744977912
Brontojoris said on Jan 3, 2006 at 3:48 PM :
One thing to note about isNumeric is that unlike isDefined, you should not
put quotes around the variable you want to check. ie:

isDefined("url.somevar") versus isNumeric(url.somevar)
Mediahouse said on May 22, 2007 at 8:04 PM :
Mocax.

I have tested your theory using Coldfusion MX 7,0,2,142559

isNumeric(str) returns false when the string is outside the range of;
2.225074*10-308 to 1.797693*10+308

suggesting that the function attempts to convert the string to a DOUBLE FLOAT.

for what reason you will ever use a number that large is beyond me.
halL said on May 29, 2007 at 12:31 PM :
Mediahouse is correct.

IsNumeric returns NO (false) if ColdFusion cannot convert a string into its internal numeric representation.
The string Mocax posted is too large to convert.

In fact, if you tried the following:

<cfset foo=1797693134862315807937289714053034150799341327100378269361737789804449682927647509466490179775872070963302864166928879109465555478519404026306574886715058206819089020007083836762738548458177115317644757302700698555713669596228429148198608349364752927190741684443655107043427115596995080930428801779041744977912>
<cfset bar = foo + 3>

You'd get an error message indicationg that the value 1797693134862315807937289714053034150799341327100378269361737789804449682927647509466490179775872070963302864166928879109465555478519404026306574886715058206819089020007083836762738548458177115317644757302700698555713669596228429148198608349364752927190741684443655107043427115596995080930428801779041744977912 cannot be converted to a number.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt1135.htm