subTotal += carts.Amount * product.Price;
Cannot implicitly convert type 'int?' to 'double'. An explicit conversion exists (are you missing a cast?)
subTotal += carts.Amount * product.Price;
Cannot implicitly convert type 'int?' to 'double'. An explicit conversion exists (are you missing a cast?)
Here
subTotal += carts.Amount * product.Price;
you try to implicitly convert an int?
to an int
(carts.Amount
). Solution:
if (carts.Amount.HasValue) {
subTotal += carts.Amount.Value * product.Price;
} else {
//carts.Amount is null, handle it
}
You can use Convert.ToDouble(x)
where x is the int value. Check out https://msdn.microsoft.com/en-us/library/ayes1wa5(v=vs.110).aspx for more information (this is C#, but its similar in the other Cs)
int? nullableIntVal = 100; var dblVal = Convert.ToDouble(nullableIntVal.GetValueOrDefault(0));