Cursor ca2 = dbh1.getReadableDatabase().query(DatabaseHelper.TABLE_NAME, null, null, null, null, null, null);
int countTotal = ca2.getCount();
Cursor ca1 = dbh1.getReadableDatabase().query(DatabaseHelper.TABLE_NAME, null, DatabaseHelper.VALUE6 + "='Automatic'", null, null, null, null);
int count = ca1.getCount();
int percentTrans = ((count/countTotal)*100);
statText=(EditText)findViewById(R.id.etext3);
statText.setText(Integer.toString(percentTrans));
Toast toast=Toast.makeText(this, Integer.toString(percentTrans), 2000);
toast.show();
Hello , i have a silly problem here. I want to the percentage by dividing count over countTotal and multiplying that by 100. percentTrans is integer by nature and this value will be passed to an edit text which requires that percentTrans be converted to string. count is 2 and countTotal is 3. But i get 0 as the result. Any ideas?
count/countTotalisinttoo and(int)(2/3)is0.write it as
(count*100/countTotal)