When I make an account to get the % of a number, I have a problem, I explain:
I take 5% out of 7.74 and it's 0.3870 but I want you to only show me two numbers in the decimal part, that is < strong> 0.38 How can I do this?
And another doubt that I have, is it possible that the result is with a , and not a . ?
This is how I do the process:
public class MainActivity extends AppCompatActivity {
EditText uno;
TextView tres;
Button btn1;
static final BigDecimal PORCENTAJE_CINCO = new BigDecimal("0.05");
public BigDecimal calculaCincoPorCiento(BigDecimal numero) {
return numero.multiply(PORCENTAJE_CINCO);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uno = (EditText) findViewById(R.id.uno);
tres = (TextView) findViewById(R.id.tres);
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BigDecimal aux0 = new BigDecimal(uno.getText().toString());
BigDecimal aux1 = calculaCincoPorCiento(aux0);
tres.setText(aux1 + " " + "es el 5%");
}
});
}
}
Thank you!