1
這裏有一個方法,我有:陣列沒有在Java中正確插入數據/ Android的
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;
}
有三個記錄,使三個環路應happneing。 totalMonthlyFee返回爲90.然而,數據是8.33,45和45.我試圖得到的總和(98.33應該是正確的,但我越來越90?)。任何人都可以看到這裏擰什麼?
謝謝。那是我需要的。 +1 – KickingLettuce