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

Not sure what this means.  Can someone point me in the right direction?

Here is my code:

{

id = id + .0001;-----------------------------------------------------------Error Occurs Here
}
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Billing EngineerCommented:
this will work better:
``````id = id + (decimal).0001;
``````
Billing EngineerCommented:
or shorter:
``````id += (decimal).0001;
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

OwnerAuthor Commented:

Thanks
Kenny
Chief Technology OfficerCommented:
Angel's answer is the right one, but in the spirit of making shorter, you can do this as well.

``````id += .0001m;
``````
Commented:

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
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.