2

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
  • 6,224
  • 24
  • 77
  • 113
  • 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) – Ignasi 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,001
  • 1
  • 13
  • 25
0
double d = 420000382.34;
System.out.println(BigDecimal.valueOf(d)+"");
Eritrean
  • 15,851
  • 3
  • 22
  • 28