View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Val PreviousNext

Val

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)

IsNumeric

Parameter

Description

string

A string or a variable that contains one

This function works as follows:

<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>

Contents > CFML Reference > ColdFusion Functions > Val PreviousNext

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

Version 6.1

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

Comments


Lupus 23 said on Sep 28, 2005 at 8:47 AM :
It isn't mentioned in this description, but Val() will also work for floating point numbers as well.

Val(12.25) will return 12.25

 

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

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/funca116.htm