double

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
What are you using to display the answer? Have you tried applying a custom
numerical format to the output field? One that specifies the number of
decimal places to show?


"(e-mail address removed)"
 
(e-mail address removed)
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.2046226218487756653985343291424214839935302734375

The result of that is

1999.999999999999945040100116476417915737440070438800604826767859378833
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.
 
Back
Top