1 //关于浮点数的各个知识点总结: 2 public class FloatTest 3 { 4 public static void main(String[] args) 5 { 6 float af = 5.2345556f; 7 //下面将看到af的值已经发生了改变 8 System.out.println(af); 9 10 double a = 0.0; 11 double c = Double.NEGATIVE_INFINITY; 12 float d = Float.NEGATIVE_INFINITY; 13 //看到float和double的负无穷大是相等的 14 System.out.println(c == d); //true 15 16 //0.0除以0.0将得到非数NaN 17 System.out.println(a/a); //输出NaN 18 19 //两个非数之间是不相等的。 20 System.out.println(a/a == Float.NaN);//false 21 22 //所有正无穷大都相等 23 System.out.println(6.0/0 == 555.0/0);//true 24 25 //负数除以0将得到负无穷大 26 System.out.println(-8/0); 27 28 //下面代码将抛出除以0异常: 29 /* 30 Exception in thread "main" java.lang.ArithmeticException: / by zero 31 at FloatTest.main(FloatTest.java:19) 32 */ 33 System.out.println(0/0); 34 } 35 }