1
double d = 5000000000000000000034534534d;
System.out.println(String.valueOf(d)); // prints 5.0E27

Now, I want to display complete number instead of scientific notation.

As a fix, I have added new Bigdecimal which works fine till 10-12 digits not for big numbers.

System.out.println(new BigDecimal(d).toString()) // prints 4999999999999999791559868416

which is not same as double value. Need a solution to print correct number as double till 25 digits.

Sunny
  • 91
  • 1
  • 13

1 Answers1

1

Your double value contains way too many significant digits and it can't be stored into a double.

You need to use a BigDecimal.

Please have a look to this SO answer about the reason Why should we use BigDecimal instead of Double in the real world?

Community
  • 1
  • 1
abarisone
  • 3,707
  • 11
  • 35
  • 54