1

I have

double a= = 13;
double b = 6;
double c = a/b;

I want to make sure it returns in three decimals. I tried

Math.round(c); //gives me an error instead.
ivesingh
  • 888
  • 3
  • 12
  • 30

1 Answers1

1

If you need to format the output, for example to print it or display it in a textview, use:

DecimalFormat threeDecRound = new DecimalFormat();
threeDecRound.setMaximumFractionDigits(3);
threeDecRound.setRoundingMode(RoundingMode.HALF_DOWN);
threeDecRound.format(number)
Vikram
  • 51,313
  • 11
  • 93
  • 122