Converts numeric characters that occur at the beginning of a string to a number.
A number. If conversion fails, returns zero.
Conversion functions, String functions
Val(string)
| Parameter | Description |
|---|---|
| string |
A string or a variable that contains one |
This function works as follows:
TestValue = "234A56?7'", Val(TestValue) returns 234
TestValue = "234'5678'9?'", Val(TestValue) returns 234TestValue = "BG234", Val(TestValue) returns the value 0, (not an error)TestValue = "0", Val(TestValue) returns the value 0, (not an error)<h3>Val Example</h3>
<cfif IsDefined("FORM.theTestValue")>
<cfif Val(FORM.theTestValue) is not 0>
<h3>The string <cfoutput>#DE(FORM.theTestValue)#</cfoutput>
can be converted to a number:
<cfoutput>#Val(FORM.theTestValue)#</cfoutput></h3>
<cfelse>
<h3>The beginning of the string <cfoutput>#DE(FORM.theTestValue)#
</cfoutput> cannot be converted to a number</h3>
</cfif>
</cfif>
<form action = "val.cfm">
<p>Enter a string, and determine whether its beginning can be evaluated
to a numeric value.
<p>
<input type = "Text"
name = "TheTestValue"
value = "123Boy">
<input type = "Submit"
value = "Is the beginning numeric?"
name = "">
</form>
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.
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-pt2114.htm
Comments
No screen name said on Aug 26, 2003 at 7:20 AM : beadingo said on Aug 11, 2004 at 2:54 AM : ivanmca said on Sep 23, 2004 at 10:31 AM :