My code:
int inStock = -3;
product.AVG = 0; // double
receiptIt.Quantity = 3; // int
decimal newPrice = 755.23m;
product.SPD = 79.80m; // decimal
var newAvg = (inStock * (float) product.AVG + (receiptIt.Quantity * (float) newPrice)) / (inStock + receiptIt.Quantity);
var newAvgWithSpd = newAvg + (float) product.SPD;
Why is my result in compiled program this?:
newAvg => 0
newAvgWithSpd => Infinity
But in Immediate window in Visual Studio is result as expected:
newAvg => Infinity
newAvgWithSpd => Infinity
How can this be possible in c#?:
var a = -3 * 0 + (3 * 755.23) / (-3 + 3);
var b = a + 79.80;
//Result:
a => 0; // <<=== WHY?
b => Infinity;
I can reproduce it on:
- production server (Windows server 2016, Release build, Asp.net core 1)
- development machine (Windows 10 64-bit, Debug build, Asp.net core 1, Debug with breakpoint )
But can't reproduce it on: - development machine (Windows 10 64-bit, Debug build, Asp.net core 1, Debug with Immediate Window)
EDIT: newAvg is initialized...