For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > February 2005 > -0,1 + 0,1 = -0,27559 E17 ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author -0,1 + 0,1 = -0,27559 E17 ?
Evitan

2005-02-11, 4:01 am

I'm not saying i'm a good programmer, in fact i'm rather new at Visual Basic.
But I did do night-school for Delphi for a year and i have made little
programs for about 20 years.
I think I'm overlooking something very basic, but I can't find the problem.
In General declarations, option explicit :
Dim a as Double
Dim b as Double
Dim c as Double

at one point i have the following line :

c = a - b
Now, i have used a Watch for all, and even made labels to show the value of
each variable.
Just before the calculation a = -0.1 and b = 0.1
but c is -0,27955....E17 instead of 0

I start of with a value of - 0,4 for a, and each step i add 0,1
everything works fine untill c is suposed to be 0

I know it has to be a stupid little thing i'm missing but i can't find it.
I tried different names for the variables, changed the code to c = a + 0,1
instead of using the b variable, gave the value of a to another variable and
used that one instead. i've been trying things for over 6 hours...

So, If any of you have an idea, I would be greatfull if you'd let me know.
Bob Butler

2005-02-11, 4:01 am

"Evitan" <Evitan@discussions.microsoft.com> wrote in message
news:B6AB44AE-4B38-4EEE-A7D9-F179A1BC171C@microsoft.com
> I'm not saying i'm a good programmer, in fact i'm rather new at
> Visual Basic. But I did do night-school for Delphi for a year and i
> have made little programs for about 20 years.
> I think I'm overlooking something very basic, but I can't find the
> problem. In General declarations, option explicit :
> Dim a as Double
> Dim b as Double
> Dim c as Double


Welcome to the world of floating point math; the issue you have is not
VB-specific but manifests itself in any system that uses floating point
values. Use Currency, Decimal or Integer or Long values if you need to
avoid the errors.

for more info:
http://support.microsoft.com/defaul...kb;en-us;279755

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Bob Butler

2005-02-11, 4:01 am

"Evitan" <Evitan@discussions.microsoft.com> wrote in message

Please don't multipost; I just wasted my time searching out the reference
because I hadn't seen this post in the other newsgroup yet where it has
several responses already.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Duane Bozarth

2005-02-11, 4:01 am

Bob Butler wrote:
>
> "Evitan" <Evitan@discussions.microsoft.com> wrote in message
>
> Please don't multipost; I just wasted my time searching out the reference
> because I hadn't seen this post in the other newsgroup yet where it has
> several responses already.


I second Bob's complaint...see the link I posted in the .discussion
thread...
Ed

2005-02-11, 4:01 am

On Thu, 10 Feb 2005 19:26:27 -0800, "Bob Butler" <tiredofit@nospam.com>
wrote:

>"Evitan" <Evitan@discussions.microsoft.com> wrote in message
>
>Please don't multipost; I just wasted my time searching out the reference
>because I hadn't seen this post in the other newsgroup yet where it has
>several responses already.


Maybe if used a better reader then Microsoft Outlook Express you
wouldn't have that problem. ;p

Duane Bozarth

2005-02-11, 4:03 pm

Ed wrote:
>
> On Thu, 10 Feb 2005 19:26:27 -0800, "Bob Butler" <tiredofit@nospam.com>
> wrote:
>
>
> Maybe if used a better reader then Microsoft Outlook Express you
> wouldn't have that problem. ;p


Wasn't the reader...
Rick Rothstein

2005-02-11, 4:03 pm

> Maybe if used a better reader then Microsoft Outlook
> Express you wouldn't have that problem. ;p


Do you mean you have a news reader that will search out all of the other
newsgroups out there, find identical Subject postings by the same person
and automatically link them together for you as if the OP had cross
posted his individual messages in the first place? Please, tell me the
name of this wonder product; I definitely want to get it.

Rick

Rick Rothstein

2005-02-11, 4:03 pm

> > Please don't multipost; I just wasted my time searching out the
reference
has[color=darkred]
>
> I second Bob's complaint...see the link I posted in the .discussion
> thread...


And I'll third that!!!

Rick - MVP

Jeff Johnson [MVP: VB]

2005-02-11, 4:03 pm


"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:Ohgd6pEEFHA.2508@TK2MSFTNGP09.phx.gbl...

>
> Do you mean you have a news reader that will search out all of the other
> newsgroups out there, find identical Subject postings by the same person
> and automatically link them together for you as if the OP had cross
> posted his individual messages in the first place? Please, tell me the
> name of this wonder product; I definitely want to get it.


The Sarcasm of the Day award goes to: Rick Rothstein!!


argusy

2005-02-11, 9:00 pm

Sarcastic?... maybe
I think I'll join the queue behind Rick for the wonder product.
I hope I'm still alive when it arrives!!
Argusy

Jeff Johnson [MVP: VB] wrote:
> "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> news:Ohgd6pEEFHA.2508@TK2MSFTNGP09.phx.gbl...
>
>
>
>
> The Sarcasm of the Day award goes to: Rick Rothstein!!
>
>


Tony Proctor

2005-02-14, 9:01 am

See Q279755

Tony Proctor

"Evitan" <Evitan@discussions.microsoft.com> wrote in message
news:B6AB44AE-4B38-4EEE-A7D9-F179A1BC171C@microsoft.com...
> I'm not saying i'm a good programmer, in fact i'm rather new at Visual

Basic.
> But I did do night-school for Delphi for a year and i have made little
> programs for about 20 years.
> I think I'm overlooking something very basic, but I can't find the

problem.
> In General declarations, option explicit :
> Dim a as Double
> Dim b as Double
> Dim c as Double
>
> at one point i have the following line :
>
> c = a - b
> Now, i have used a Watch for all, and even made labels to show the value

of
> each variable.
> Just before the calculation a = -0.1 and b = 0.1
> but c is -0,27955....E17 instead of 0
>
> I start of with a value of - 0,4 for a, and each step i add 0,1
> everything works fine untill c is suposed to be 0
>
> I know it has to be a stupid little thing i'm missing but i can't find it.
> I tried different names for the variables, changed the code to c = a + 0,1
> instead of using the b variable, gave the value of a to another variable

and
> used that one instead. i've been trying things for over 6 hours...
>
> So, If any of you have an idea, I would be greatfull if you'd let me know.



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com