From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Returns the numeric equivalent of the passed string. This function is the same as the Val function but is international-savvy.


result = Cdbl(string)
result = stringVariable.CDbl

Part Type Description
result Double The numeric equivalent of the string passed, if a numeric equivalent exists.
string String Any valid string expression.
stringVariable String Any variable of type String.


Use Val if you control the string that is passed, and use CDbl if the string comes from the user. You should use CDbl instead of Val if the string contains separators.

See the Val function for more information.

CDbl returns zero if string contains no numbers, except in the special case where the string begins with the string “NAN”. In this case, it returns "NAN(021)".

Numbers are converted only if they are found at the beginning of the string. Any numbers that follow a non-numeric value are ignored.


 "1AA2" returns 1
 "AA2" returns 0
 "12AA54" returns 12

Sample Code

This code use the CDbl function to return the numbers contained in a String.

Dim n As Double
n = CDbl("12345") // returns 12345
n = CDbl("54.05car45") // returns 54.05
n = CDbl("123.45") // returns 123.45
n = CDbl("123 45") // returns 123
n = CDbl("123,456") // returns 123456
n = CDbl("auto") // returns 0
n = CDbl("&hFFF") // returns 4095
n = CDbl("&b1111") // returns 15

This code shows both usages of CDbl.

Dim d As Double
Dim s As String

s = "65.4"
d = s.CDbl

See Also

CLong, CStr, Double.FromText, Format, IsNumeric, Str, Val functions.