User Guide
Chapter 2: ColdFusion Functions 553
Val
Returns a number that the beginning of a string can be converted to. Returns 0 if
conversion is not possible.
See also IsNumeric.
Syntax Val(
string
)
string
Any string.
Examples <!--- This example shows Val --->
<HTML>
<HEAD>
<TITLE>
Val Example
</TITLE>
</HEAD>
<BODY BGCOLOR=silver>
<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" METHOD="POST">
<P>Enter a string, and discover if
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>
</BODY>
</HTML>