Decimal Percision - short code, strange problem
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/867f655285c0e04d/8a59fb7d2904c775?tvc=1&q=saar+decimal#8a59fb7d2904c775Could anyone help me to understand why in the following code sum1 is different from sum2?
Basically it's the same calculation done. Keep in mind the x is 28 digits so it's within the range of decimal.
decimal x = (-0.0084682975822291150192357277M);
decimal sum1 , sum2;
sum2 = (3500.91M * x) + (x * 3500M + 822m);
sum1 = (3500.91M * x) + (x * 3500M) + 822m;
Console.WriteLine (sum1);
Console.WriteLine (sum2);
------------
Well, the reason is that the decimal type precision s not 28 right to the decimal digit, but 28 digits overall. Thanks for those who answered.