Re: Singles to Doubles
- From: "Karl E. Peterson" <karl@xxxxxxxx>
- Date: Mon, 16 Jul 2007 12:56:28 -0700
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
.
- Follow-Ups:
- Re: Singles to Doubles
- From: Steve Gerrard
- Re: Singles to Doubles
- From: Rick Rothstein \(MVP - VB\)
- Re: Singles to Doubles
- From: Jim Mack
- Re: Singles to Doubles
- From: dpb
- Re: Singles to Doubles
- References:
- Singles to Doubles
- From: Karl E. Peterson
- Re: Singles to Doubles
- From: Bob Butler
- Singles to Doubles
- Prev by Date: Re: Singles to Doubles
- Next by Date: Re: VB6 - why isnt a straight Win32 DLL offered as a project type?
- Previous by thread: Re: Singles to Doubles
- Next by thread: Re: Singles to Doubles
- Index(es):
Relevant Pages
|