473,507 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

double

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?
Jul 21 '05 #1
2 1314
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?
"no***@online.knorrassociates.com"
<no***************************@discussions.microso ft.com> wrote in message
news:FD**********************************@microsof t.com...
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?

Jul 21 '05 #2
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
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
9850
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double...
20
17747
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
31
6575
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
10
8635
by: Robert Palma | last post by:
I'm having trouble figuring out how to pass a pointer to a double array (1 dimensional) to a C function. Declaring array as: double xx; Declaring func. int process( double *input ) Calling...
10
18738
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
3
2863
by: BlueTrin | last post by:
I am using a DLL written in C, it uses some pointers on functions, I have defined a wrapper around it in C# which uses some delegates: #region Delegates and Marshalling to call solvopt public...
67
9816
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
1
8202
by: JWest46088 | last post by:
I keep getting these error messages: area(double,double) in Rectangle cannot be applied to () return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter(); ...
2
5579
by: dj10fld | last post by:
I am getting a (cannot convert double to double in assignment errors) here is a part of my code #include <iostream> #include <iomanip> #include <cmath> using namespace std; #define MaxSize...
2
5753
by: Genro | last post by:
#include<stdio.h> #include<TX/graphics.h> #include<time.h> // I need help! struct Krug{ double _x; double _y; double _skox; double _skoy; double...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.