比如

System.out.println(0.14*100);

输出: 14.000000000000002

 

解决方法:

BigDecimal b = new BigDecimal(String.valueOf(0.14));
        BigDecimal c = new BigDecimal(String.valueOf(100));
        System.out.println(b.multiply(c));
        System.out.println(b.multiply(c).intValue());
        System.out.println(b.multiply(c).doubleValue());

输出: 

14.00
14
14.0

posted on 2016-06-25 09:40  woqiaoxun  阅读(3026)  评论(0编辑  收藏  举报