0

please help me with for loop

I must print numbers [12, 13] and number should be increased by 0.1

for(double i = 12.0; i < 13.1; i = i + 0.1){
    System.out.println(i);
}

Output

12.0
12.1
12.2
12.299999999999999
12.399999999999999
12.499999999999998
12.599999999999998
12.699999999999998
12.799999999999997
12.899999999999997
12.999999999999996
13.099999999999996

Why did not it display output like this:

12.1 , 12.2, 12.3, 12.4 , 12.5, 12.6 , 12.7 ..... 13 
Rogue
  • 11,105
  • 5
  • 45
  • 71
Frebush
  • 1
  • 4

0 Answers0