public static void main(String[] args) {
float a = 3f, b = 0.1f, c = 0.3f;
System.out.println("boolean:" + (a * b == c));
System.out.println("boolean:" + (0.1 * 3 == 0.3));
System.out.println("boolean:" + (3 * 0.1 == 0.3));
System.out.println(3 * 0.1);
System.out.println(4 * 0.1);
System.out.println("boolean:" + (4 * 0.1 == 0.4));
System.out.println(1 * 0.3);
System.out.println("boolean:" + (1 * 0.3 == 0.3));
}
boolean:true
boolean:false
boolean:false
0.30000000000000004
0.4
boolean:true
0.3
boolean:true
https://www.zhihu.com/question/56545018
网友评论