I am trying to get a data type (int
, decimal
etc.) of a variable of var {type}
:
var ratingSum = ratings.Sum(x=>x.Rating);//7
var ratingCount = ratings.Count();//2
decimal avgValue = decimal.Parse((ratingSum / ratingCount).ToString());//getting 3
var avgValue2 = (ratingSum / ratingCount).ToString(); //getting 3
I am unable to get exact value of avgValue
or avgValue2
to check if it is of int
or decimal
. I always get 3 instead of 3.5.
If ratingSum
is 8 and ratingCount
is 2 my output should be 4 that means avgValue
is of int
.