Here is a method I have:
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;
}
There are three records so three loops should be happneing.
totalMonthlyFee is being returned as 90. However, the data is 8.33, 45 and 45. I am trying to get the sum of that (98.33 should be correct but I am getting 90?). Anyone see what is wring here?
On second thought if I understand what you are doing I don’t think you need the inner loop at all. Maybe try this…