decimal rounding is off for (276/304)*304

If you put the following code in your compiler the result is a bit bizar:

decimal x = (276/304)*304;
double y = (276/304)*304;

Console.WriteLine("decimal x = " + x);
Console.WriteLine("double y = " + y);

Result:

decimal x = 275.99999999999999999999999

double y = 276.0

Can someone explain this to me? I don't understand how this can be correct.

7
задан mskfisher 9 May 2012 в 19:19
поделиться