Somewhere in your code, you are using floats, not doubles.
Try the following in a console app (C#):
static void Main(string[] args)
{
double a = 0.1;
double b = 0.2;
double c = a + b;
double d = 0.1 + 0.2;
float e = 0.1f;
float f = 0.2f;
double g = e + f;
Console.WriteLine("a={0}", a);
Console.WriteLine("b={0}", b);
Console.WriteLine("c={0}", c);
Console.WriteLine("d={0}", d);
Console.WriteLine("e={0}", e);
Console.WriteLine("f={0}", f);
Console.WriteLine("g={0}", g);
Console.Read();
}

Signature
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
Nope.
still not right. the console outputs correct but the underlying numbers are
wrong which fails the unit testing in my application.
Check out this screen shot:
http://www.bgeek.net/photos/d/3559-2/screen.jpg
Cheers
Owen Evans
Cowboy - MVP (Gregory A. Beamer) wrote:
> Somewhere in your code, you are using floats, not doubles.
I think you'll find that the default formatting is leading you astray.
> Try the following in a console app (C#):
>
[quoted text clipped - 11 lines]
> Console.WriteLine("b={0}", b);
> Console.WriteLine("c={0}", c);
This prints 0.3, yes, but c is not 0.3. Try
Console.WriteLine("c={0}", c-0.3);
> Console.WriteLine("d={0}", d);
Doing the addition at compile time doesn't help, either, try
Console.WriteLine("d={0}", d-0.3);
> Console.WriteLine("e={0}", e);
> Console.WriteLine("f={0}", f);
> Console.WriteLine("g={0}", g);
It's only apparent in this example with float and not double because
double's default ToString rounds to a point which hides the
discrepancy, but float's doesn't (it has a bigger disrecpancy too).
> Console.Read();
> }
In any event, more digits of precision would just be a palliative -
better to fix the real problem, and use an exact type (as I'm sure you
are aware).
--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using