0

I am making a java program in which i have to round off the double digit to seven place but I don't know how to do it. like 6.6666667e-10 to 0.0000001

Nicolas Filotto
  • 41,524
  • 11
  • 90
  • 115
Nicky Manali
  • 386
  • 3
  • 22

1 Answers1

1

The reason it return 0 is because the number example is too small. it can't be rounded to 7 digits after decimal point because the first nonzero digit in it's full decimal representation is after the 7th digit.

However, for slightly bigger numbers, this code should do the trick:

double a = 6.66666667E-10;
DecimalFormat df = new DecimalFormat("#.#######");
df.setRoundingMode(RoundingMode.CEILING);
System.out.println(df.format(a));
ItamarG3
  • 3,974
  • 6
  • 29
  • 42