Doubt with decimals Android (BigDecimal)


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);

    protected void onCreate(Bundle savedInstanceState) {

        uno = (EditText) findViewById(;
        tres = (TextView) findViewById(;

        btn1 = (Button) findViewById(;

        btn1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                BigDecimal aux0 = new BigDecimal(uno.getText().toString());
                BigDecimal aux1 = calculaCincoPorCiento(aux0);
                tres.setText(aux1 + " " + "es el 5%");

Thank you!

asked by UserNameYo 19.05.2017 в 15:59

1 answer


You can use setScale to show the number of decimals you want, and also, you can put it if you want to round it halfway up or down. Here is an example of rounding up with two decimals:

BigDecimal bd = new BigDecimal(3.33333);
bd = bd.setScale(2, RoundingMode.HALF_UP);

To show it with a , instead of a . you can convert it to String and then substitute the . for a , :

TextView tv = (TextView)findViewById(;
BigDecimal bd = new BigDecimal(3.33333);
answered by 19.05.2017 / 16:04