Re: Field changed from Single to Double issue..

Tech-Archive recommends: Fix windows errors by optimizing your registry

anonymous_at_discussions.microsoft.com
Date: 08/11/04


Date: Wed, 11 Aug 2004 06:23:42 -0700

If I look at the single field, it says "0.3", period,
not "0.30000001" or anything like that -- it was entered
by hand as 0.3 so there is no precision issue with it.

However, after the conversion from single to double, it
does say "0.3000001192" (regardless of the exact number of
zeroes after the 3). This just doesn't make sense unless
the single was also 0.3xxxxxxxxxxxx, imo, and it wasn't..
I really don't want to code anything as I've got like 200
fields in this situation and they are all doing this sort
of thing -- sigh!

>-----Original Message-----
>I think you're missing two zeros in the precision there...
>
>It's well-known that binary can only represent decimal to
it's level of
>precision.
>
>For a table field (single), 0.30000001 (6 zeros) seems to
run off the scale so
>get's truncated (or in your case vice-versa). But
actually a single can store
>much higher precision than that (13 zeros in the example)
according to tests
>on a "Dim s as Single". And both a single and double in
code present 0.3 as
>0.3, so it's confusing isn't it?
>-----
>Still, I s'pose you wanted a resolution...
>
>I think you've found a limitation of the way table
conversions work. It may be
>a "bug" but regardless it's a fact.
>
>You could maybe do your conversions via a Recordset. I
haven't tested that,
>just that conversions in code seem to work better.
>
>If it's critical (like for your accountant), see if one
of the PRECISE formats
>suits, like integer(multiplied) or currency.
>
>It's dangerous to use "=" in comparing floating point
numbers, which are
>unlikely to be to infinite precision (though I see in
code sample comparisons
>it says "near enough" at some point. You can use >=0.3 or
maybe
>Format(single,"blah-blah")=0.3 or some other rounding
truncation to control
>the precision.
>
>(tested A2000 and A2002)
>Chris
>
>"DN" <anonymous@discussions.microsoft.com> wrote in
message
>news:3b4f01c47f28$35729e60$a501280a@phx.gbl...
>> I have an Access 2000 DB (I think it's 2000, it's
>> whatever comes with Visual Studio 6.0).. Simply put, I
>> have a field that is of type "Single" that contains the
>> value 0.3. When I modify that field and make
>> it "Double", access automatically converts the values,
as
>> it should, but returns 0.300001192 in the field.. I
>> understand that there can be precision issues sometimes
>> in comparisons and such, but is this NORMAL for Access
to
>> do as well? Is there any simple work around or patch?
I
>> suppose I can write an SQL statement to take care of
>> this, but that isn't something I want to do as there are
>> many fields. . . Thanks!
>
>
>.
>



Relevant Pages

  • Re: Floating point to integer casting
    ... Conversions in such cases are required to discard extra ... precision and range. ... when deciding when to simplify expressions. ... "The values of floating operands and of the results of floating ...
    (comp.lang.c)
  • Re: Floating point to integer casting
    ... Conversions in such cases are required to discard extra ... precision and range. ... when deciding when to simplify expressions. ... Some floating point hardware works internally using 80-bits, when the precision of double is 64-bits, which can lead to inconsistencies when intermediate 80-bit results are written to memory as 64-bits then loaded again, compared with keeping the intermediate values in the registers. ...
    (comp.lang.c)
  • RE: Undocumented alternate form for %#f ?
    ... conversions, the first character of the output string is made ... zero. ... No difference with the alternate specification here as the precision is ... This gives the minimum number of digits to appear for d, i, o, ...
    (comp.lang.python)
  • Re: Field changed from Single to Double issue..
    ... >by hand as 0.3 so there is no precision issue with it. ... >>I think you're missing two zeros in the precision ... >conversions work. ... >>You could maybe do your conversions via a Recordset. ...
    (microsoft.public.access.conversion)
  • Re: Undocumented alternate form for %#f ?
    ... conversions, the first character of the output string is made ... zero. ... No difference with the alternate specification here as the precision is ... This gives the minimum number of digits to appear for d, i, o, ...
    (comp.lang.python)