CDbl

From Xojo Documentation
Jump to: navigation, search
Method

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

Syntax

result=Cdbl(string)
OR
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.

Notes

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.

So,

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

Examples

These examples 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 example shows both syntaxes of CDbl.

Dim d As Double
Dim s As String

s = "65.4"
d = s.CDbl
d.Cdbl(s)

See Also

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

Double.FromText

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About