Re: Singles to Doubles



Hi Bob --

What the heck? Seems silly to have to convert it to a String first, then
to a Double. But, it is more accurate. Anyone know of a less ugly way to
accurately replicate a Single with a Double, or this the best it gets?

Isn't it mainly that the Single isn't representing the value as accurately?

I guess, yeah. But how is it that a *String* seems to do so even more accurately?
For discussion purposes, I modified your example just a bit:

Public Sub Main()
Dim s As Single
Dim d1 As Double
Dim d2 As Double
s = 0.3026!
d1 = s
d2 = CDbl(CStr(s))
Debug.Print s, d1, d2
Debug.Print s = d1, s = d2
Debug.Print s - d1, s - d2
End Sub

Which gives me these results:

0.3026 0.302599996328354 0.3026
True True
0 -3.67164609826887E-09

And, of course, the value I'm after *is* 0.3026 -- not the one that's off
0.00000000367... Seems like some sort of register garbage that I'm picking up in
the conversion?

Thanks... Karl
--
..NET: It's About Trust!
http://vfred.mvps.org


.



Relevant Pages

  • Re: Concurrency violation
    ... Public Sub SendAllSMS() ... Dim ds As New Data.DataSet ... Dim NewDat As String ... Public Property ODBC_ConnectionStringAs String ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • RE: Practical Macro Size Limit?
    ... Public Sub myProject ... Dim B As String ... Temping with Staffmark ... in Rock Hill, SC ...
    (microsoft.public.excel.programming)
  • WMS Plugins:How to modify authorization to URL ?
    ... How to modify authorization to URL? ... Public Sub AuthorizeEvent(_ ... Dim strUser As String = "" ... ' TODO: Handle plug-in events. ...
    (microsoft.public.windowsmedia.sdk)
  • Re: Filewatch saga continues
    ... Public Sub NKWatch_Created(ByVal sender As Object, ... Dim frmFirst As New Form1 ...
    (microsoft.public.dotnet.general)
  • Re: Problems with Concurency Violation
    ... Public Sub SendAllSMS() ... Dim ds As New Data.DataSet ... Dim NewDat As String ... Public Property ODBC_ConnectionStringAs String ...
    (microsoft.public.dotnet.framework.adonet)