Examples: CDbl function

Example 1

' Convert string to double
' Display value and data type
Dim nvar As Variant
Dim nstr As String
nstr = Inputbox("Number", "Enter any number", "0")
If Isnumeric(nstr) Then
	nvar = Cdbl(nstr)
	Messagebox nvar,, Typename(nvar)
Else
	Messagebox nstr,, "Not a number"
End Sub

Example 2

' Convert the sum of two Single values to Double.
Dim x As Single
Dim y As Single
Dim result As Double
x! = 11.06E23
y! = 6.02E23
result# = CDbl(x! + y!)
Print result#              ' Prints 1.70800003057064E+24