Alex Rivera | Logout

c#: sum of two double numbers problem

Asked 2011-03-22T09:04:28.650
9

Possible Duplicate:
Why is floating point arithmetic in C# imprecise?

Hi. I've got following problem:

43.65+61.11=104.75999999999999

for decimal is correct:

(decimal)43.65+(decimal)61.11=104.76

Why result for double is wrong?

Edit
Report

1 Answer

2

Because double uses a fractional model. Any number < 1 is expressed in the form of x / y. Given that information, some numbers can only be approximated. Use decimal, not double for high precision calculations.

See here for some light reading :)

answered 2011-03-22T09:08:01.130

Your Answer