I have the following query. Why do I get zero as the value in the percent column?
var qPercentage = from q in qCounts
select new {
开发者_如何学C q.Category,
q.CategoryCouplet,
q.Subcategory,
Percent = 100*(q.Count / iTotal)
};
Counts has valid integer values, by the way!
It looks like you're doing integer division within the parenthesis. Try
100*(q.Count / (double)iTotal)
or if you want Percent to be an integer
(100 * q.Count) / iTotal
Because q.Count and iTotal are integer. You should do 100 * q.Count / iTotal
.
Try
Percent = 100*((float)q.Count / iTotal)
精彩评论