Re: Losing precision when converting to double
Jon Skeet <[email protected]> Mon, 30 Oct 2006 19:57:31 +0000
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Mikael Bergforsen wrote: > 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? Please read http://www.pobox.com/~skeet/csharp/floatingpoint.html Jon =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com