View comments | RSS feed

Val

Description

Converts numeric characters that occur at the beginning of a string to a number.

Returns

A number. If conversion fails, returns zero.

Category

Conversion functions, String functions

Function syntax

Val(string)

See also

IsNumeric

Parameters

Parameter Description

string

A string or a variable that contains one

Usage

This function works as follows:

Example

<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 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


MikerRoo said on Oct 13, 2005 at 2:21 AM :
Val () does not work with either commas or exponents.
This is a bug that should be documented here and fixed.

For example:
" 32,767" becomes 32
"-32,767" becomes -32
" 1.18E-38" becomes 1.18
"-1.18E-38" becomes -1.18

etc., etc.
CFTycoon67 said on Aug 25, 2006 at 12:19 PM :
The val function also has a 12 digit limit. Anything longer than twelve digits will be converted to an exponent. Doh!

13 Digit Example:

val(1234567890123) returns 1.23456789012E+012

 

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

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000661.htm