Solved

Error 2 Operator '+' cannot be applied to operands of type 'decimal' and 'double'

Posted on 2008-11-06
Medium Priority
1,012 Views
Not sure what this means.  Can someone point me in the right direction?

Here is my code:

{

id = id + .0001;-----------------------------------------------------------Error Occurs Here
}
0
Question by:kwh3856

LVL 143

Expert Comment

ID: 22895189
this will work better:
``````id = id + (decimal).0001;
``````
0

LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 22895193
or shorter:
``````id += (decimal).0001;
``````
0

Author Closing Comment

ID: 31513908

Thanks
Kenny
0

LVL 60

Expert Comment

ID: 22895313
Angel's answer is the right one, but in the spirit of making shorter, you can do this as well.

``````id += .0001m;
``````
0

LVL 37

Expert Comment

ID: 22898251

id = id + (decimal) .0001;

says ...

id is equal to id plus the conversion of the double value .0001 to a decimal.

id += .0001m; or id = id + .0001m;

says ...

id is equal to id plus .0001

While these two may SEEM to be equivalent they are not because of how floating point math works on computers. Since floating point numbers are handled by approximations ... on some machines (or some JIT implementations) you may end up with a scenario where the first bit of code for an id of 1 returns

2.000100000003

where the second one would return

2.0001

For more details I would suggest reading http://docs.sun.com/source/806-3568/ncg_goldberg.html

Cheers,

Greg
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month15 days, left to enroll