Re: Subtraction Bug in VB
- From: "Ken Halter" <Ken_Halter@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 4 Aug 2005 09:20:22 -0700
"Sarav" <Sarav@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7291609B-89C9-4F2C-A452-977112654FE1@xxxxxxxxxxxxxxxx
> Hi Experts,
>
> I am having a peculiar issue in VB while subtracting two number in
> the range 0.1,0.2 & 0.3.
>
> Let us have an example. Goto Immediate window give the command like
> this.
> ?10 - 9.9 obviously we expect the result as 0.1. But what VB returns is
> like
> this : 9.99999999999996E-02. For all other number values it returns good.
> I
> know upon using the Round() function I can get 0.1. But I want to know Why
> VB
> behaves like this especially for the results like 0.1 and 0.2.
>
> If anybody does know the answer, please post it here.
>
> -Sarav
The answer is... it's not a bug. It directly relates to the way PCs store
floating point numbers.
See "What Every Computer Scientist Should Know About Floating-Point
Arithmetic"
http://cch.loria.fr/documentation/IEEE754/ACM/goldberg.pdf
INFO: Visual Basic and Arithmetic Precision
http://support.microsoft.com/default.aspx?scid=kb;en-us;279755
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
.
- Follow-Ups:
- Re: Subtraction Bug in VB
- From: Michael J. Strickland
- Re: Subtraction Bug in VB
- From: Tony Proctor
- Re: Subtraction Bug in VB
- References:
- Subtraction Bug in VB
- From: Sarav
- Subtraction Bug in VB
- Prev by Date: Subtraction Bug in VB
- Next by Date: Re: Subtraction Bug in VB
- Previous by thread: Subtraction Bug in VB
- Next by thread: Re: Subtraction Bug in VB
- Index(es):
Relevant Pages
|