H
H
hasanshaih2020-05-03 19:19:30
Java
hasanshaih, 2020-05-03 19:19:30

Why is the double value not exact?

When increasing the value of double, floating point values ​​are not exact, for example:

public class Main{

    static double ii = 0;

    public static void main(String[] args) {
              for (double i = 0; i <= 10; i+=0.000_001) {
            ii+=0.000_001;
        }
        System.out.println(ii);
    }
}


As a result, I get: 10.000000999267517
Why can't I get exactly 10?

Why is this happening?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question