How do I format the value of a double variable on android?

Asked

Viewed 320 times

2

I am making a small application that aims to calculate the BMI of a person, but I am not able to format the output of the value to only two decimal places always looks like: 22.222222 or 31.23232322 etc... I have tried to use the "%. 2f", but Textview n accepts. someone can help me?

1 answer

3

Try it like this:

double dub = 31.2323232;
meuEditText.setText(String.format( "%.2f", dub ));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.