1
2
3
4
5
6
7
8 @author
9
10 public class FloatingPointErrors {
11
12 public static void main(String[] args) {
13
14
15 System.out.println(.1 * .1);
16
17
18 System.out.println(.3 * .7);
19
20
21 System.out.println(.2 * .7);
22
23
24 double x = .1 * 10;
25 double y = .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1;
26 System.out.println(x);
27 System.out.println(y);
28
29
30 boolean same1 = (x == y);
31 System.out.println("Equal? : " + same1);
32
33 boolean same2 = (Math.round(x) == Math.round(y));
34 System.out.println("Equal? : " + same2);
35 }
36 }