美文网首页
0.1 * 3 == 0.3 笔记

0.1 * 3 == 0.3 笔记

作者: ShihChieh_Ma | 来源:发表于2020-06-09 22:51 被阅读0次
    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

    相关文章

      网友评论

          本文标题:0.1 * 3 == 0.3 笔记

          本文链接:https://www.haomeiwen.com/subject/qrkytktx.html