What is CDbl doing?
Posted
by Dan Tao
on Stack Overflow
See other posts from Stack Overflow
or by Dan Tao
Published on 2010-04-16T12:49:40Z
Indexed on
2010/04/16
13:03 UTC
Read the original article
Hit count: 451
I had until recently been under the impression that the CDbl(x)
operation in VB.NET was essentially a cast (i.e., the VB equivalent of (double)x
in C#); but a recent discovery has revealed that this is not the case.
If I have this string:
Dim s As String = "12345.12345-"
And I do this:
Dim d As Double = CDbl(s)
d
will be set to the value -12345.12345
! Now, don't get me wrong, this is kind of convenient in my particular scenario; but I have to admit I'm confused as to why this works. In particular, I'm confused because:
Double.Parse
does not work with the above input.Double.TryParse
does not work.Convert.ToDouble
does not work.
How is CDbl
so clever?
© Stack Overflow or respective owner