Both were hoping for a 0.41 result, but the result was not what I expected. I know this result is a floating point difference. Is there a way to always get the expected result without worrying about doing this kind of floating point arithmetic in Java?
public class Main {
public static void main(String[] args) {
System.out.println(41 / 100.0);
System.out.println(41 * 0.01);
}
}
Printed output:
0.41
0.41000000000000003