0

this code below is return a very strange result. It should return 0.0008, but is return 8.202154101077051E-4. Can anyone help me to solve this?

    double d1 = 0.0099;
    double d2 = 12.0700;
    double d3 = d1/d2;
    System.out.println(d3);

1 Answers1

3

Explanation

It should return 0.0008

It does.

"E" is a format for numbers that are either very big or very close to 0. If an E(value) stands behind a number, that basically means "take this number and multiply it by 10 ^ value".

If you take 8.202154101077051 x 10 ^ -4, you will get 0.0008202154101077051, which is approximatly 0.0008.

Solution

How you can format numbers when printing them out is explained in this stackoverflow answer.

Cactusroot
  • 1,019
  • 3
  • 16