Whatever message this page gives is out now! Go check it out!

Val

Last update:
May 18, 2026

Description

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

Returns

A number. If conversion fails, returns zero.

Category

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>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page