3
I am learning to program, I am making an application with 3 edittext (where I insert the numbers I want to calculate) and a textview to present the result. I would like to know how to calculate 2 numbers with option to fill the third edittext. And I wonder how I can convert my result to 2 decimal places.
I leave the code here:
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 + "€" );
}
}
It is done :). Regarding the edittext calculation, we imagine for example 5 boxes where we insert 5 numbers and multiply these 5 numbers and get the result, my idea is to have the option to multiply for example only 2 boxes
– S0nkit3