I'm learning to program, I'm doing an application with 3 edittext (where I enter the numbers I want to calculate) and a textview to display the result. I would like to know how to calculate 2 numbers with option to be able to fill the third edittext. And I would like to know how I can convert my result to 2 decimal places.
I leave here the code:
public void somar (View v){
EditText odd1 = (EditText) findViewById(R.id.editText7);
String stringodd1 = odd1.getText().toString();
EditText odd2 = (EditText) findViewById(R.id.editText8);
String stringodd2 = odd2.getText().toString();
EditText odd3 = (EditText) findViewById(R.id.editText9);
String stringodd3 = odd3.getText().toString();
EditText montante = (EditText) findViewById(R.id.editText12);
String stringmontante = montante.getText().toString();
if (stringodd1.trim().isEmpty() || stringodd2.trim().isEmpty() || stringodd3.trim().isEmpty())
{
Toast.makeText(getApplicationContext(), "Campos em branco",
Toast.LENGTH_LONG).show();
}
else
{
double valorodd1 = Double.parseDouble(stringodd1);
double valorodd2 = Double.parseDouble(stringodd2);
double valorodd3 = Double.parseDouble(stringodd2);
double valormontante = Double.parseDouble(stringmontante);
double resu = valorodd1 * valorodd2 * valorodd3 * valormontante;
TextView resultado = (TextView) findViewById(R.id.textView15);
resultado.setText (resu + "€" );
}
}