i have following case
beleg.PreisDB = (double?)orders.Where(x => x.orderId == beleg.auftrnr).Sum(x => x.itemPrice + x.shippingPrice + x.giftWrapPrice) ?? 0;
beleg.PreisCouponDB = (double?)orders.Where(x => x.orderId == beleg.auftrnr).Sum(x => x.itemPromotionDiscount + x.shipPromotionDiscount) ?? 0;
var gesamtPreis = Math.Round(beleg.PreisDB??0 + beleg.PreisCouponDB??0, 2);
I have added a quickwatch in debug to some fields in my case:
beleg.PreisDB == 8.39
beleg.PreisDB??0 == 8.39
beleg.PreisCouponDB == -0.49
beleg.PreisCouponDB??0 == -0.49
And now the strange behaviour also from quickwatch and of course the result
beleg.PreisDB??0 + beleg.PreisCouponDB??0 == 8.39
Math.Round(beleg.PreisDB??0 + beleg.PreisCouponDB??0, 2) == 8.39
gesamtPreis == 8.39
So the addition of 8.39 + -0.49 doesn't give me 7.9 but 8.39 This code was running for 600k cases on at least two i had this behaviour the others behaved well. I'm to blind to see my error at the moment. The question is why is .net behaving like this? I'm Using Visual Studio 2015 with .net 4.5.2.