how do I format the value of a double variable in android?

2

I am making a small application that aims to calculate the IMC of a person, but I am not able to format the output value to only two decimal places always something like: 22.222222 or 31.23232322 etc ... I have tried to use the "% .2f", but TextView does not. Can someone help me?

    
asked by anonymous 02.12.2015 / 21:23

1 answer

3

Try this:

double dub = 31.2323232;
meuEditText.setText(String.format( "%.2f", dub ));
    
02.12.2015 / 22:32