1

I have a double value, which can have a big value. Therefore it will display a number containing an E character. How can I get the original big value from that double?

Example:

double d = 420000382.34;
System.out.println(d);

output will be:

4.2000038234E8

But I want this output somehow:

420000382.34

victorio
  • 5,766
  • 17
  • 71
  • 105
  • Possible duplicate of [How to round a number to n decimal places in Java](http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java) – ilopezluna Dec 15 '16 at 08:48

2 Answers2

4

There are multiple way to print double in normal number without E notation

    DecimalFormat df = new DecimalFormat("#");
    df.setMaximumFractionDigits(2);
    System.out.println(df.format(d));

or you can use printf

System.out.printf("%.2f", d);

or you can do something as below

System.out.println(String.format("%.2f", d));
Zia
  • 1,122
  • 11
  • 24
0
double d = 420000382.34;
System.out.println(BigDecimal.valueOf(d)+"");
Eritrean
  • 13,003
  • 2
  • 20
  • 25