I am running a simple query and calculating the percentage of two values. Every time this run's the calculation returns zero. The calculation is cast to a decimal also, so I can't see what the problem is.
from e in db.hours
select new
{
OverTimeHoursPercentage = (decimal)((1088 / 22000) * 100)
};
After the query is ran, I can see in the debugger, the type of OverTimeHoursPercentage is a decimal
, and that the value calculated is zero when it should be 4.94
.
Any ideas of whats going on?
1088/ 22000
is notdecimal
, it's anint
division. AddM
to one of the constants to fix this problem, e.g.1088M / 22000