My textview prints really long values such as 2130.18700102321401240. How do I make it shorter? is there a way to make it 2130.18 ? (round off the value to the nearest )
TV_BMR.setText("BMR: " + Double.toString(BMR));
My textview prints really long values such as 2130.18700102321401240. How do I make it shorter? is there a way to make it 2130.18 ? (round off the value to the nearest )
TV_BMR.setText("BMR: " + Double.toString(BMR));
is there a way to make it 2130.18 ?
No, round to the nearest it would be 2130.19.
To achieve that,you can use %2f
to get two decimal places
TV_BMR.setText("BMR: " + String.format("%.2f", BMR));
Example
public class Program {
public static void main(String[] args) {
double a = 2130.18700102321401240;
System.out.println("Before : "+a);
System.out.println("After : " + String.format("%.2f", a));
}
}
Output
Before : 2130.187001023214
After : 2130.19