Losing precision when converting to double

Mikael Bergforsen <[email protected]> Mon, 30 Oct 2006 07:46:34 -0500
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <LISTSERV%[email protected]>
Whenever the result of an operation is a double I loose precision; here
are some examples:

double a = 1111.111111111;  //a = 1111.1111111109999 OK

converting from decimal
double a = Convert.ToDouble(1111.111111111M); //a = 1111.111083984375 NOT
OK

result of addition
double a = 1111.111111111;
double b = 1111.111111111;
double c = a + b; //c = 2222.22216796875 NOT OK
double c = 2222.222222222; // c = 2222.2222222219998 OK

Any idea why this happens?

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com