kwh3856
asked on
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:
if (reader.HasRows)
{
id = Convert.ToDecimal(reader[" id"].ToStr ing());
id = id + .0001;-------------------- ---------- ---------- ---------- ---------E rror Occurs Here
Session.Add("id", id);
}
Here is my code:
if (reader.HasRows)
{
id = Convert.ToDecimal(reader["
id = id + .0001;--------------------
Session.Add("id", id);
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
your awesome but your title already shows that;)......congrats on that new title.
Thanks
Kenny
Thanks
Kenny
Angel's answer is the right one, but in the spirit of making shorter, you can do this as well.
id += .0001m;
actually mwvisa1 your answer is correct and here is why ....
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_goldbe rg.html
Cheers,
Greg
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
Cheers,
Greg
Open in new window