-1

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));
  • you can use a decimal formater. https://stackoverflow.com/questions/17082115/set-double-format-with-2-decimal-places – David Dennis Sep 08 '17 at 03:04

1 Answers1

1

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
John Joe
  • 12,412
  • 16
  • 70
  • 135