Decimal a = 42.485M;
Decimal b = 48M;
Decimal c = a / b;
Console.WriteLi ne(c.ToString() );
gives the result 0.8851041666666 666666666666667
The correct, exact answer is .885.
I know that floating point types cannot represent some values
precisely, but the decimal type (which is a base 10 FP type) CAN
represent these three values (the dividend, divisor, and quotient)
exactly.
Furthermore, doc states that "The result of an operation on values of
type decimal is that which would result from calculating an exact
result (preserving scale, as defined for each operator) and then
rounding to fit the representation. "
Could someone explain this unexpected result?
Decimal b = 48M;
Decimal c = a / b;
Console.WriteLi ne(c.ToString() );
gives the result 0.8851041666666 666666666666667
The correct, exact answer is .885.
I know that floating point types cannot represent some values
precisely, but the decimal type (which is a base 10 FP type) CAN
represent these three values (the dividend, divisor, and quotient)
exactly.
Furthermore, doc states that "The result of an operation on values of
type decimal is that which would result from calculating an exact
result (preserving scale, as defined for each operator) and then
rounding to fit the representation. "
Could someone explain this unexpected result?
Comment