Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (3.5k points)

I want to print a double value in Java without exponential form.

double dexp = 12345678;

System.out.println("dexp: "+dexp);

It shows this E notation: 1.2345678E7.

I want it to print it like this: 12345678

What is the best way to prevent this?

1 Answer

0 votes
by (46k points)

You could try printf() with %f:

double dexp = 12345678;

System.out.printf("dexp: %f\n", dexp);

This will indent dexp: 12345678.000000. If you don't require the fractional part, use

System.out.printf("dexp: %.0f\n", dexp);

This practices the format specifier language described in the documentation.

The default toString() format used in your unique code is spelled out here.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...