I made a simple code whis keeps adding 0.1 to zero. this is the code:
static double num = 0;
    public static void main(String[] args) {
        num+=0.1;
        System.out.println(num);
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        main(null);
    }
}
This is what it outputs:
0.1
0.2
0.30000000000000004
0.4
0.5
0.6
0.7
0.7999999999999999
0.8999999999999999
0.9999999999999999
1.0999999999999999
...
But I want the output to look like this:
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
...
Any ideas why it does that or how to fix it please?
 
     
     
    