这是我的一个方法:
public double getCombinedAprThisMonth() {
Cursor c = database.rawQuery("SELECT * FROM debt;", null);
double totalMonthlyFee = 0;
double SingleAprRate = 0;
double[] storeFees;
int rows = c.getCount();
storeFees = new double[c.getCount()];
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
for (int i = 0; i < rows; i++) {
String BalColumn = c.getString(c
.getColumnIndex("debt_total"));
String AprColumn = c.getString(c.getColumnIndex("apr"));
double aprColumn = Double.valueOf(BalColumn);
double balColumn = Double.valueOf(AprColumn);
SingleAprRate = (((aprColumn / 100) / 12) * balColumn);
storeFees[i++] = SingleAprRate;
}
}
for(double i : storeFees) {
totalMonthlyFee += i;
}
c.close();
return totalMonthlyFee;
}
有三个记录,所以应该发生三个循环。totalMonthlyFee 返回为 90。但是,数据是 8.33、45 和 45。我试图得到总和(98.33 应该是正确的,但我得到的是 90?)。有人看到这里出了什么问题吗?