I have a table in SQLite with this structure:
String CREATE_TOTAL_PRICE = "CREATE TABLE " + TOTAL_PRICE + "("
+ KEY_TPID + " INTEGER PRIMARY KEY,"
+ KEY_TPRICE + " REAL" + ")";
I am trying to get the sum total of all column values of column KEY_TPRICE. I am using this method which seems to work:
public int getTotalOfAmount() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery("SELECT SUM(total_price) FROM " + TOTAL_PRICE, null);
c.moveToFirst();
int i = c.getInt(0);
c.close();
return i;
}
But the problem comes when the value is being displayed.
You see i have data input as 50.01,5.5 and when getting the sum total i get 55 which is not really the case.
The real total is 55.51 when i run the query externally.
I have tried setting REAL,INTEGER, FLOAT,DOUBLE as my column data type but still
What exactly is rounding up my figures? Please asssist me with suggestions.
Aucun commentaire:
Enregistrer un commentaire