Val
Converts numeric characters and the first period found that occur at the beginning of a string to a number.
A period not accompianied by at least one numeric digit will be ignored. If no numeric digits are found at the start of the string, zero will be returned.
Method Signature
Val(string=[string])
Arguments
Argument
Type
Required
Description
Default
string
string
true
The string to parse
Examples
Numeric characters at beginning and middle of a string
val( "120test12sstring" );
Result: 120
Numeric characters only at the end of a string
val( "string98" );
Result: 0
Additional Examples
dump( Val( "1234 Main St." ) ); // 1234
dump( Val( "Main St., 1234" ) ); // 0
dump( Val( "123.456" ) ); // 123.456
dump( Val( "" ) ); // 0
dump( Val( "1" ) ); // 1
dump( Val( "one" ) ); // 0
dump( Val( "123T456" ) );
// 123
Related
Last updated
Was this helpful?