no***@online.knorrassociates.com
<no***************************@discussions.microso ft.com> wrote:
I'm trying to multiply two doubles and assign the result to a double as well.
But it seems the result is rounded up.
x = 907.18474
y = 2.2046226218487757
the result I calculate 1999.999999999999902722818
But this is calculated to be 2000.0.
I looked up double and it is specified as follows;
double ?5.0 ? 10?324 to ?1.7 ? 10308
Precision: 15-16 digits
What am I missing here?
See
http://www.pobox.com/~skeet/csharp/floatingpoint.html
You're actually multiplying
907.1847400000000334330252371728420257568359375
by
2.204622621848775665398534329142421483993530273437 5
The result of that is
1999.999999999999945040100116476417915737440070438 800604826767859378833
23640562593936920166015625
The two exactly representable numbers closest to that are
1999.999999999999772626324556767940521240234375
and
2000
2000 is closer to the actual number than the number slightly lower than
it, hence your result.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too