So one of my students were working on basic equations in computer science and one of them had a weird bug when they wrote the following code.
import java.io.*;
import java.util.*;
public class randomnum{
public static void main(String[] args){
double incorrectnum = 4.3+6.26;
System.out.println(incorrectnum);
double correctnum = 4.2+6.36;
System.out.println(correctnum);
}
here, the two print statements should be identical, 10.56. However, the first double prints 10.559999999999 and the other one prints 10.56. For the life of me, I can't fathom why. they're logically identical and both carry any numbers the same way (in this case carrying over 0 numbers), so I don't see where the discrepancy occurs. Any insight would be great!
I tried multiple different double equations and almost all of them worked as intended besides this one.