浮点数扩展

浮点数扩展

浮点数能表现的字长是有限的,也是离散的,浮点数存在舍入误差
很多数字没法精确表示,所以只能是一个大约数
public class Demo02 {
    public static void main(String[] args) {
        // 浮点数扩展
        float f = 0.1f; // 0.1
        double d = 1.0/10; // 0.1
        System.out.println(f==d); // false

        float d1 = 2313131313131313131f;
        float d2 = d1+1;
        System.out.println(d1==d2); // true
        /*
        浮点数能表现的字长是有限的,也是离散的,浮点数存在舍入误差
        很多数字没法精确表示,所以只能是一个大约数
         */
    }
}
posted @ 2020-04-22 19:16  阿亮在努力  阅读(222)  评论(0)    收藏  举报