public void onButtonClick(View v) {
int n1, n2, n3;
double calc;
EditText e1 = (EditText)findViewById(R.id.first_grade);
EditText e2 = (EditText)findViewById(R.id.second_grade);
EditText e3 = (EditText)findViewById(R.id.third_grade);
TextView t1 = (TextView)findViewById(R.id.calculate);
n1 = Integer.parseInt(e1.getText().toString());
n2 = Integer.parseInt(e2.getText().toString());
n3 = Integer.parseInt(e3.getText().toString());
calc = (n1 + n2 + n3)/3;
t1.setText(String.format("%.2f", calc));
}
This is my code and I have tried DecimalFormat as well, but none of the solutions from the stackoverflow work for me.
If I put 11, 22, 10 respectively as an input, I should get a result of 14.333333, but I am getting 14.00 for the result.
Anyone know how to fix this error? Or have solution to this?