hello friends that I have a doubt to get the percentage in Android is that I saw how it was done in android and it is supposed to be similar this is my code in android: Where I'm supposed to do this
sum2 = to a total of a previous operation ini = is the value I entered
and it is assumed that in java the percentage is removed like this
percentage = (number / 100) * amount; an example
someone can help me I get very high numbers
package com.example.danhermes.despensa;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast;
public class pantry extends AppCompatActivity implements View.OnClickListener {
EditText etdisponible, etcompra, etcantidad, etarticulo, etinicio;
Button btncomprar, btnaceptar;
TextView tvporcentaje;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.despensa);
etdisponible = (EditText) (super.findViewById(R.id.etdisponible));
etcompra = (EditText) (super.findViewById(R.id.etcompra));
etcantidad = (EditText) (super.findViewById(R.id.etcantidad));
etarticulo = (EditText) (super.findViewById(R.id.etarticulo));
etinicio = (EditText) (super.findViewById(R.id.etinicio));
btncomprar = (Button) (super.findViewById(R.id.btncomprar));
btnaceptar = (Button) (super.findViewById(R.id.btnaceptar));
tvporcentaje = (TextView) (super.findViewById(R.id.tvporcentaje));
btncomprar.setOnClickListener(this);
btnaceptar.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.btnaceptar) {
try {
//tabla=Float.parseFloat(et_tabla.getText().toString());
String inicio=etinicio.getText().toString();
String articulo=etarticulo.getText().toString();
String cantidad=etcantidad.getText().toString();
int ini=Integer.parseInt(inicio);
int art=Integer.parseInt(articulo);
int cant=Integer.parseInt(cantidad);
double suma=(ini-art*cant);
String resultadosuma=String.valueOf(suma);
etdisponible.setText(resultadosuma+ " Cantidad Restante");
double suma2=(ini-suma);
String resultadosuma2=String.valueOf(suma2);
etcompra.setText(resultadosuma2+ " Total de Compras");
double porcentaje=(suma2/100)*ini;
String porciento=String.valueOf(porcentaje);
tvporcentaje.setText(porciento);
} catch (NumberFormatException e) {
Toast toast = Toast.makeText(this, "Favor de escribir numeros", Toast.LENGTH_SHORT);
toast.show();
}
}
else if(view.getId()==R.id.btncomprar){
Toast toast = Toast.makeText(this, "Favor de escribir Compras", Toast.LENGTH_SHORT);
toast.show();
}
}
}