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

History

ColdFusion (2018 release): Introduced named parameters.

Function syntax

Val(value)

See also

IsNumeric

Parameters

Parameter

Description

value

A string or a variable that contains one

Usage

This function works as follows:

  • If TestValue = "234A56?7'", Val(TestValue) returns 234.
  • If TestValue = "234'5678'9?'", Val(TestValue) returns 234.
  • If TestValue = "BG234", Val(TestValue) returns the value 0, (not an error).
  • If TestValue = "0", Val(TestValue) returns the value 0, (not an error).

Example

<cfscript>
    val1="234A56?7"
    writeOutput(Val(val1) & "<br/>")
    val2="234'5678'9?'"
    writeOutput(Val(val2) & "<br/>")
    val3="BG234"
    writeOutput(Val(val3) & "<br/>")
    val4="0"
    writeOutput(Val(val4) & "<br/>")
</cfscript>

 Adobe

Get help faster and easier

New user?