轻松搞定Math.ceil,Math.round,Math.floor三者的区别

来源:互联网 发布:卡通设计软件 编辑:程序博客网 时间:2024/06/08 11:11
   double a = 0.1;        double b = 0.50;        double c = 0;        double d = 0.4;        double e = 0.6;        double f = 1.3;        double g = 1.6;        //Math.ceil 表示的是大于某个小数的最小整数的double值;  ceiling最高限度 天花板        double ceil1 = Math.ceil(a);        double ceil2 = Math.ceil(b);        double ceil3 = Math.ceil(c);        double ceil4 = Math.ceil(d);        double ceil5 = Math.ceil(e);        //Math.round  表示的是四舍五入,且得到long值        long round1 = Math.round(a);        long round2 = Math.round(b);        long round3 = Math.round(c);        long round4 = Math.round(d);        long round5 = Math.round(e);        //Math.floor 跟Math.ceil相反,表示的是小于某个小数的最大整数值的double类型; floor底板 最底限度        double floor1 = Math.floor(a);        double floor2 = Math.floor(b);        double floor3 = Math.floor(c);        double floor4 = Math.floor(d);        double floor5 = Math.floor(e);        double floor6 = Math.floor(f);        double floor7 = Math.floor(g);

这里写图片描述

0 0