为什么我将平均值等于零

时间:2015-04-15 07:43:20

标签: java

我不知道为什么我得到平均值= 0.下面的代码显示了我如何计算它,下面张贴的图像显示了我得到的输出

代码

    float avg = (goodMatchesList.size()/rawMatchesListSorted.size()) * 100;
    Log.D(TAG, "descMatcher", "avg: " + avg);
    Log.D(TAG, "descMatcher", "min: " + minDist);
    Log.D(TAG, "descMatcher", "max: " + maxDist);
    Log.D(TAG, "descMatcher", "objComputedDescExt.rows: " + matFactory.getComputedDescExtMatAt(0).rows());
    Log.D(TAG, "descMatcher", "rawMatchesListSorted.size: " + rawMatchesListSorted.size());
    Log.D(TAG, "descMatcher", "goodMatchesList.size: " + goodMatchesList.size());

enter image description here

1 个答案:

答案 0 :(得分:5)

您正在划分两个整数 - (goodMatchesList.size()/rawMatchesListSorted.size()),因此如果结果小于1,则它变为0。

对于浮点除法,请使用强制转换:

((float)goodMatchesList.size()/rawMatchesListSorted.size())*100
如果您不关心分数,则在分割之前

或乘以100:

100*goodMatchesList.size()/rawMatchesListSorted.size()