Hallo, ich stehe vor einem seltsamen problem.
Ich habe eine SQLite DB, die bestens funktioniert. Darin speichere ich fast ausschließlich "DECIMAL(8.3) NOT NULL) Werte. 
Nun möchte ich diese Werte natürlich auch auslesen und verrechnen. 
Das klappt auch ganz gut, solange ich keine Zahl mit 2 oder mehr Nachkommastellen auslese.
Gespeichert werden diese Zahlen korrekt in der Datenbank, nur scheint beim verrechnen gewaltig was daneben zu laufen.
Speichere ich eine Zahl mit 2 oder 3 Nachkommastellen, bekomme ich einfach keinen Wert mehr durch gegeben.
Hier der code dazu:
MainActivity, in der die TextViews gefüllt werden:
public void calc() {
		// Get text for the statistics
		amount_widget.setText(db.getSearchResult("amount", 0));
		lpayment_widget.setText(db.getSearchResult("price", 0));
		tpayment_widget.setText(db.getSearchResult("total_price", 1));
		mileage_widget.setText(db.getSearchResult("mileage", 2));
		trefueled_widget.setText(db.getSearchResult("amount", 1));
		// Calculate text for the consumption
		double consumption = (Double.parseDouble(db
				.getSearchResult("amount", 1)) / Double.parseDouble(db
				.getSearchResult("mileage", 2))) * 100;
		consumption = Math.round(consumption * 100) / 100.0;
		consumption_widget.setText(consumption + "L /100km");
	}
	
			Alles anzeigen
	DbAdapter Activity, in der Die DB ausgelesen, und die Werte je nach übergebenen cmd Wert verrechnet werden:
public String getSearchResult(String sql, int cmd) {
		if (cmd == 0) {
			String countQuery = "SELECT " + sql + " FROM " + TABLE_NAME
					+ " WHERE _id = (SELECT max(_id) FROM " + TABLE_NAME + ")";
			Cursor cursor = db.rawQuery(countQuery, null);
			String tmp = cursor.moveToFirst() ? cursor.getString(0) : "0";
			cursor.close();
			return tmp;
		} else if (cmd == 1) {
			double sum = 0;
			String countQuery = "SELECT " + sql + " FROM " + TABLE_NAME;
			String idQuery = "SELECT _id FROM " + TABLE_NAME
					+ " WHERE _id = (SELECT max(_id) FROM " + TABLE_NAME + ")";
			Cursor cursor = db.rawQuery(countQuery, null);
			Cursor id = db.rawQuery(idQuery, null);
			// berechnung
			cursor.moveToFirst();
			id.moveToFirst();
			int maxId = Integer.parseInt(id.getString(0));
			for (int i = 0; i < maxId; i++) {
				double tmp = Integer.parseInt(cursor.getString(0));
				sum = sum + tmp;
				cursor.moveToNext();
			}
			cursor.close();
			id.close();
			return String.valueOf(sum);
		} else if (cmd == 2 && sql == "mileage") {
			double sum = 0;
			String countQuery = "SELECT " + sql + " FROM " + TABLE_NAME;
			String idQuery = "SELECT _id FROM " + TABLE_NAME
					+ " WHERE _id = (SELECT max(_id) FROM " + TABLE_NAME + ")";
			Cursor cursor = db.rawQuery(countQuery, null);
			Cursor id = db.rawQuery(idQuery, null);
			// berechnung
			cursor.moveToFirst();
			id.moveToFirst();
			int maxId = Integer.parseInt(id.getString(0));
			if (maxId > 1) {
				int array[] = new int[maxId];
				// Array füllen
				for (int i = 0; i < maxId; i++) {
					array[i] = Integer.parseInt(cursor.getString(0));
					// sum = sum + tmp;
					cursor.moveToNext();
				}
				for (int k = 1; k < maxId; k++) {
					double tmp;
					tmp = array[k] - array[k - 1];
					sum = sum + tmp;
				}
				cursor.close();
				id.close();
				return String.valueOf(sum);
			} else {
				return "--";
			}
		}
		return "Wrong CMD";
	}
	
			Alles anzeigen
	Ich hoffe wirklich, dass einer von euch versteht, warum das so dermaßen abspackt...